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

import com.alibaba.fastjson.JSON;
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
import com.yonge.cooleshow.biz.dal.enums.MessageSendMode;
import com.yonge.cooleshow.biz.dal.enums.MessageTypeEnum;
import com.yonge.cooleshow.biz.dal.enums.SendStatusEnum;
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.io.Serializable;
import java.util.Date;
import java.util.Optional;

/**
 * 系统消息表
 * 2022-11-15 17:59:45
 */
public class SysMessageWrapper {

    /**
     * 消息查询条件
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class SysMessageQuery {

        // 关键字匹配
        private String keyword;

        // 发送人编号
        private Long userId;

        // 用户类型
        private ClientEnum clientType;

        // 状态，0,待发送;1,发送中;2,发送完成
        private SendStatusEnum status;

        // 接收人编号
        private String receiver;

        // 标题
        private String title;

        // 消息类型；1，表示短信；2，表示邮件; 3,app推送消息
        private MessageSendMode type;

        // 客户端STUDENT,TEACHER,BACKEND,SCHOOL
        private ClientEnum clientId;

        // 0:未读，1：已读
        private Boolean readStatus;

        // 发送时间
        private Date sendTime;

        private Long messageConfigId;

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

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

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

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


    @Data
    @ApiModel("未读消息统计")
    public static class MessageUnreadStat implements Serializable {

        @ApiModelProperty("消息分组")
        private String group;

        @ApiModelProperty("未读消息数")
        private Integer number;
    }

    /**
     * 消息设置一键读取条件
     */
    @Data
    public static class MessageRead {

        private MessageTypeEnum messageType;
    }

}
