package com.yonge.cooleshow.biz.dal.wrapper.im;

import com.alibaba.fastjson.JSON;
import com.microsvc.toolkit.common.response.paging.QueryInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.text.MessageFormat;
import java.util.Date;
import java.util.Objects;
import java.util.Optional;

/**
 * 群成员表
 * 2022-11-26 10:55:18
 */
@ApiModel(value = "ImGroupMemberWrapper对象", description = "群成员表查询对象")
public class ImGroupMemberWrapper {

    @Data
	@Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel(" ImGroupMemberQuery-群成员表")
    public static class ImGroupMemberQuery implements QueryInfo {
    
    	@ApiModelProperty("当前页")
        private Integer page;
        
        @ApiModelProperty("分页行数")
        private Integer rows;
        
        @ApiModelProperty("关键字匹配")
		private String keyword;

        @ApiModelProperty("群组ID")
        private String groupId;

        public static ImGroupMemberQuery from(String json) {
            return JSON.parseObject(json, ImGroupMemberQuery.class);
        }

        public String getKeyword() {
            return Optional.ofNullable(keyword).filter(StringUtils::isNotBlank).orElse(null);
        }
    }

    @Data
	@Builder
    @NoArgsConstructor
    @AllArgsConstructor
	@ApiModel(" ImGroupMember-群成员表")
    public static class ImGroupMember {

                
		@ApiModelProperty("主键;") 
		private Long id;

        @ApiModelProperty("群组主键Id")
        private Long imGroupId;

		@ApiModelProperty("群组ID") 
		private String groupId;

		@ApiModelProperty("群组名称")
		private String groupName;
                        
		@ApiModelProperty("用户ID") 
		private Long userId;
                        
		@ApiModelProperty("用户身份") 
		private String clientType;
                        
		@ApiModelProperty("用户头像") 
		private String avatar;
                        
		@ApiModelProperty("昵称;") 
		private String nickname;
                        
		@ApiModelProperty("是否是管理员") 
		private Boolean isAdmin;
                        
		@ApiModelProperty("群角色TEACHER老师、STUDENT学生") 
		private String roleType;
                        
		@ApiModelProperty("修改时间") 
		private Date updateTime;
                        
		@ApiModelProperty("创建时间") 
		private Date createTime;

        @ApiModelProperty("IM用户ID")
        private String imUserId;

        @ApiModelProperty("加入群组标识")
        private Boolean groupJoin;

        public static ImGroupMember from(String json) {
            return JSON.parseObject(json, ImGroupMember.class);
        }

        public String getImUserId() {
            if (StringUtils.isBlank(this.imUserId)) {
                return MessageFormat.format("{0}_{1}", String.valueOf(getUserId()), getClientType());
            }
            return this.imUserId;
        }

        public Boolean getGroupJoin() {
            return Optional.ofNullable(groupJoin).orElse(true);
        }

        public ImGroupMember avatar(String avatar) {
            this.avatar = avatar;
            return this;
        }

        public ImGroupMember nickname(String nickname) {
            this.nickname = nickname;
            return this;
        }

        public ImGroupMember id(Long id) {
            this.id = id;
            return this;
        }


        public ImGroupMember imUserId(String imUserId) {
            this.imUserId = imUserId;
            return this;
        }
    }

}