package com.wzj.soopin.im.domain.bo;

import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.core.domain.BaseBO;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import com.wzj.soopin.im.domain.SysMessage;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDateTime;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wzj.soopin.im.domain.SysMessageTemplate;

/**
 * 消息业务对象
 *
 * @author ruoyi
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ExcelIgnoreUnannotated
public class SysMessageBo extends BaseBO<SysMessage> {

    /** 主键ID */
    @ExcelProperty(value = "消息ID")
    private Long id;

    /** 发送者ID */
    private String senderId;

    /** 消息标题 */
//    @NotBlank(message = "消息标题不能为空", groups = { AddGroup.class, EditGroup.class })
    @Size(min = 0, max = 100, message = "消息标题长度不能超过100个字符")
    @ExcelProperty(value = "消息标题")
    private String title;

    /** 消息内容 */
    @NotBlank(message = "消息内容不能为空", groups = { AddGroup.class, EditGroup.class })
    @ExcelProperty(value = "消息内容")
    private String content;



    /** 发送范围（all:全部用户, userType:按用户类型, userIds:指定用户） */
    @NotEmpty(message = "发送范围不能为空", groups = { AddGroup.class })
    private Integer sendScope;

    /** 接收用户ID列表 */
    private List<Long> idList;



    /** 扩展数据（JSON格式） */
    private String extraData;



    /** 模板ID */
    private Long templateId;

    /** 状态（0正常 1停用） */
    private String status;

    /** 备注 */
    private String remark;


    private String templateType;


    /**
     * 是否发送给所有用户
     */
    private Boolean sendToAll;

    /**
     * 消息类型标识 1=指定角色 2=指定用户 3=指定群
     */
    private Integer type;

    /** 定时发送时间 */
    @ExcelProperty(value = "定时发送时间")
    @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX", timezone = "Asia/Shanghai")
    private Date scheduledTime;

    /** 触发条件 */
    @ExcelProperty(value = "触发条件")
    private String subType;

    /**
     * 模板ID
     */
    private SysMessageTemplate template;


    private Map<String, Object> templateParams=new HashMap<>();

    /** 消息类型（AUTO自动/MANUAL手动） */
//    @NotBlank(message = "消息类型不能为空", groups = { AddGroup.class, EditGroup.class })
    @ExcelProperty(value = "消息类型")
    private String msgType;

    /** 创建时间-起始 */
    @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", timezone = "UTC")
    private LocalDateTime startTime;
    /** 创建时间-结束 */
    @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", timezone = "UTC")
    private LocalDateTime sendTime;

    /**
     * 消息参数
     */
    private Map<String, Object> params;

    /**
     * 转换为查询条件
     */
    @Override
    public LambdaQueryWrapper<SysMessage> toWrapper() {
        LambdaQueryWrapper<SysMessage> lqw = new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNotBlank(this.getTitle()), SysMessage::getTitle, this.getTitle())
            .like(StringUtils.isNotBlank(this.getContent()), SysMessage::getContent, this.getContent())
            .orderByDesc(SysMessage::getCreateTime);
        return lqw;
    }
}
