package com.tourism.webadmin.back.model;

import com.baomidou.mybatisplus.annotation.*;
import com.tourism.webadmin.back.model.constant.IsTrue;
import com.tourism.common.core.util.MyCommonUtil;
import com.tourism.common.core.upload.UploadStoreTypeEnum;
import com.tourism.common.core.annotation.*;
import com.tourism.common.core.base.model.BaseModel;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Map;

/**
 * 聊天群聊成员实体对象。
 *
 * @author 吃饭睡觉
 * @date 2024-09-06
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName(value = "tour_im_member")
public class TourImMember extends BaseModel {

    /**
     * id。
     */
    @TableId(value = "id")
    private Long id;

    /**
     * 聊天群组id。
     */
    @TableField(value = "group_id")
    private Long groupId;

    /**
     * 成员角色 1群主 2管理员 3普通成员。
     */
    @TableField(value = "group_role")
    private Integer groupRole;

    /**
     * 用户id。
     */
    @TableField(value = "user_id")
    private Long userId;

    /**
     * 会话是否显示(每个群在聊天列表要不要展示) 0不显示 1显示。
     */
    @TableField(value = "is_show")
    private Integer isShow;

    /**
     * 单聊情况下对方的id。
     */
    @TableField(value = "partner_id")
    private Long partnerId;

    /**
     * 会话是否置顶 (每个群在聊天列表要不要置顶)  0不置顶 1 置顶。
     */
    @TableField(value = "is_top")
    private Integer isTop;

    /**
     * 会话是否开启免打扰 0不开启免打扰 1 开启免打扰。
     */
    @TableField(value = "is_not_disturb")
    private Integer isNotDisturb;

    /**
     * 自己在群里的昵称。
     */
    @TableField(value = "group_nickname")
    private String groupNickname;

    /**
     * 群备注。
     */
    @TableField(value = "group_remark")
    private String groupRemark;

    /**
     * 逻辑删除标记字段(1: 正常 -1: 已删除)。
     */

    @TableField(value = "data_state")
    private Integer dataState;

    /**
     * 聊天背景。
     */
    @UploadFlagColumn(storeType = UploadStoreTypeEnum.HUAWEI_OBS_SYSTEM)
    @TableField(value = "group_back_image")
    private String groupBackImage;

    /**
     * group_nickname / group_remark LIKE搜索字符串。
     */
    @TableField(exist = false)
    private String searchString;

    public void setSearchString(String searchString) {
        this.searchString = MyCommonUtil.replaceSqlWildcard(searchString);
    }

    @RelationDict(
            masterIdField = "groupId",
            slaveModelClass = TourImGroup.class,
            slaveIdField = "id",
            slaveNameField = "groupName")
    @TableField(exist = false)
    private Map<String, Object> groupIdDictMap;

    @RelationDict(
            masterIdField = "userId",
            slaveModelClass = TourUser.class,
            slaveIdField = "userId",
            slaveNameField = "showName")
    @TableField(exist = false)
    private Map<String, Object> userIdDictMap;

    @RelationDict(
            masterIdField = "partnerId",
            slaveModelClass = TourUser.class,
            slaveIdField = "userId",
            slaveNameField = "showName")
    @TableField(exist = false)
    private Map<String, Object> partnerIdDictMap;

    @RelationConstDict(
            masterIdField = "isShow",
            constantDictClass = IsTrue.class)
    @TableField(exist = false)
    private Map<String, Object> isShowDictMap;

    @RelationConstDict(
            masterIdField = "isTop",
            constantDictClass = IsTrue.class)
    @TableField(exist = false)
    private Map<String, Object> isTopDictMap;

    @RelationConstDict(
            masterIdField = "isNotDisturb",
            constantDictClass = IsTrue.class)
    @TableField(exist = false)
    private Map<String, Object> isNotDisturbDictMap;

    @RelationGlobalDict(
            masterIdField = "groupRole",
            dictCode = "GroupRole")
    @TableField(exist = false)
    private Map<String, Object> groupRoleDictMap;
}
