package com.cico.nest.lcdp.boot.core.system.dal.dataobject.notify;

import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.cico.nest.lcdp.framework.common.enums.UserTypeEnum;
import com.cico.nest.lcdp.framework.mybatis.core.dataobject.BaseDO;
import lombok.*;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * 站内信 DO
 *
 * @author zws
 */
@TableName(value = "system_notify_message", autoResultMap = true)
@KeySequence("system_notify_message_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库，可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class NotifyMessageDO extends BaseDO {

    /**
     * 站内信编号，自增
     */
    @TableId
    private Long id;
    /**
     * 用户编号
     *
     * 关联 MemberUserDO 的 id 字段、或者 AdminUserDO 的 id 字段
     */
    private Long userId;
    /**
     * 用户类型
     *
     * 枚举 {@link UserTypeEnum}
     */
    private Integer userType;

    // ========= 模板相关字段 =========

    /**
     * 模版编号
     *
     * 关联 {@link NotifyTemplateDO#getId()}
     */
    private Long templateId;
    /**
     * 模版编码
     *
     * 关联 {@link NotifyTemplateDO#getCode()}
     */
    private String templateCode;
    /**
     * 模版类型
     *
     * 冗余 {@link NotifyTemplateDO#getType()}
     */
    private Integer templateType;
    /**
     * 模版发送人名称
     *
     * 冗余 {@link NotifyTemplateDO#getNickname()}
     */
    private String templateNickname;
    /**
     * 模版内容
     *
     * 基于 {@link NotifyTemplateDO#getContent()} 格式化后的内容
     */
    private String templateContent;
    /**
     * 模版参数
     *
     * 基于 {@link NotifyTemplateDO#getParams()} 输入后的参数
     */
    @TableField(typeHandler = JacksonTypeHandler.class)
    private Map<String, Object> templateParams;

    // ========= 读取相关字段 =========

    /**
     * 是否已读
     */
    private Boolean readStatus;
    /**
     * 阅读时间
     */
    private LocalDateTime readTime;

    public NotifyMessageDO setReadStatus(Boolean readStatus) {
        this.readStatus = readStatus;
        return this;
    }

    public NotifyMessageDO setReadTime(LocalDateTime readTime) {
        this.readTime = readTime;
        return this;
    }

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

    public NotifyMessageDO setUserId(Long userId) {
        this.userId = userId;
        return this;
    }

    public NotifyMessageDO setUserType(Integer userType) {
        this.userType = userType;
        return this;
    }

    public NotifyMessageDO setTemplateId(Long templateId) {
        this.templateId = templateId;
        return this;
    }

    public NotifyMessageDO setTemplateCode(String templateCode) {
        this.templateCode = templateCode;
        return this;
    }

    public NotifyMessageDO setTemplateType(Integer templateType) {
        this.templateType = templateType;
        return this;
    }

    public NotifyMessageDO setTemplateNickname(String templateNickname) {
        this.templateNickname = templateNickname;
        return this;
    }

    public NotifyMessageDO setTemplateContent(String templateContent) {
        this.templateContent = templateContent;
        return this;
    }

    public NotifyMessageDO setTemplateParams(Map<String, Object> templateParams) {
        this.templateParams = templateParams;
        return this;
    }
}
