package com.tourism.webadmin.back.model;

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

import java.util.Map;

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

    /**
     * id。
     */
    @TableId(value ="id",type = IdType.ASSIGN_ID)
    private Long id;

    /**
     * 消息内容。
     */
    @TableField(value = "message_content")
    @UploadFlagColumn(storeType= UploadStoreTypeEnum.HUAWEI_OBS_SYSTEM)
    private String messageContent;

    /**
     * 消息类型 0文字 1文件 2系统消息。
     */
    @TableField(value = "message_type")
    private Integer messageType;

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

    /**
     * 通知消息类型 1.单聊消息 2 群聊消息 3系统消息 4关注信息 5点赞 6评论 7评论区艾特 8文章内艾特 9访问。
     */
    @TableField(value = "notice_type")
    private Integer noticeType;

    /**
     * 消息置顶/公告 0不置顶 1置顶。
     */
    @TableField(value = "is_top")
    private Integer isTop;

    /**
     * 撤回标记 0不撤回 1撤回。
     */
    @TableField(value = "revocation_tag")
    private Integer revocationTag;

    /**
     * 已经删除该条消息的用户。
     */
    @TableField(value = "deleted_by_users")
    private String deletedByUsers;

    /**
     * 已读该条消息的用户。
     */
    @TableField(value = "read_by_users")
    private String readByUsers;

    /**
     * 逻辑删除标记字段(1: 正常 -1: 已删除)。
     */
    @TableLogic
    @TableField(value = "data_state")
    private Integer dataState;

    /**
     * message_content 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;

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

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

    @RelationGlobalDict(
            masterIdField = "messageType",
            dictCode = "MessageType")
    @TableField(exist = false)
    private Map<String, Object> messageTypeDictMap;

    @RelationGlobalDict(
            masterIdField = "noticeType",
            dictCode = "TourImNoticeType")
    @TableField(exist = false)
    private Map<String, Object> noticeTypeDictMap;

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


}
