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

import com.alibaba.fastjson.JSON;
import com.yonge.cooleshow.biz.dal.enums.im.EImReceiveType;
import com.yonge.cooleshow.biz.dal.enums.im.EImSendStatus;
import com.yonge.cooleshow.biz.dal.enums.im.EImSendType;
import com.yonge.toolset.base.page.QueryInfo;
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.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 客服群发
 * 2022-12-09 10:49:10
 */
@ApiModel(value = "CustomerServiceBatchSendingWrapper对象", description = "客服群发查询对象")
public class CustomerServiceBatchSendingWrapper {

    @Data
	@Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel(" CustomerServiceBatchSendingQuery-客服群发")
    public static class CustomerServiceBatchSendingQuery extends QueryInfo {
    
        @ApiModelProperty("关键字匹配")
		private String keyword;

        @ApiModelProperty("发送声部")
        private String sendSubject;

        @ApiModelProperty("发送群体")
        private String targetGroup;

        @ApiModelProperty("发送方式")
        private EImSendType sendType;

        @ApiModelProperty("创建开始时间")
        private Date startTime;

        @ApiModelProperty("创建结束时间")
        private Date endTime;

        @ApiModelProperty("发送开始时间")
        private Date sendStartTime;

        @ApiModelProperty("发送结束时间")
        private Date sendEndTime;

        @ApiModelProperty("发送状态")
        private EImSendStatus sendStatus;

        @ApiModelProperty("发送用户ID")
        private Long sendId;

        @ApiModelProperty(value = "声部", hidden = true)
        private List<String> subjectIds;

        @ApiModelProperty(value = "用户身份", hidden = true)
        private List<String> clientTypes;
        
        public String getKeyword() {
            return Optional.ofNullable(keyword).filter(StringUtils::isNotBlank).orElse(null);
        }

        public List<String> getSubjectIds() {
            if (StringUtils.isNotBlank(getSendSubject())) {
                return Arrays.stream(getSendSubject().split(",")).collect(Collectors.toList());
            }
            return subjectIds;
        }

        public List<String> getClientTypes() {
            if (StringUtils.isNotBlank(getTargetGroup())) {
                return Arrays.stream(getTargetGroup().split(",")).collect(Collectors.toList());
            }
            return clientTypes;
        }

        public String jsonString() {
            return JSON.toJSONString(this);
        }

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

    @Data
	@ApiModel(" CustomerServiceBatchSending-客服群发")
    public static class CustomerServiceBatchSending {

        @ApiModelProperty("主键ID")
        private Long id;

        @ApiModelProperty("目标群体")
        private String targetGroup;

        @ApiModelProperty("发送声部")
        private String sendSubject;

        @ApiModelProperty("发送人数")
        private Integer sendNumber;

        @ApiModelProperty("接收人数")
        private Integer receiveNumber;

        @ApiModelProperty("目标人群")
        private EImReceiveType receiveType;

        @ApiModelProperty("发送方式")
        private EImSendType sendType;

        @ApiModelProperty("发送状态")
        private EImSendStatus sendStatus;

        @ApiModelProperty("发送时间")
        private Date sendTime;

        @ApiModelProperty("消息标题")
        private String condition;

        @ApiModelProperty("消息标题")
        private String title;

        @ApiModelProperty("文本消息")
        private String textMessage;

        @ApiModelProperty("图片消息")
        private String imgMessage;

        @ApiModelProperty("图片地址")
        private String imgUrl;

        @ApiModelProperty("客户ID")
        private Long senderId;

        @ApiModelProperty("创建用户")
        private Long createBy;

        @ApiModelProperty("创建时间")
        private Date createTime;

        @ApiModelProperty("创建用户")
        private String createUser;

        @ApiModelProperty("目标人群")
        private List<CustomerServiceReceiveWrapper.CustomerServiceReceive> receives;

        @ApiModelProperty("声部名称")
        private String subjectName;

        @ApiModelProperty("目标群体名称")
        private String targetGroupName;

        @ApiModelProperty("客服人员")
        private String sender;
        @ApiModelProperty("客服联系方式")
        private String mobile;
        
        public String jsonString() {
            return JSON.toJSONString(this);
        }

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


        public CustomerServiceBatchSending targetGroup(String targetGroup) {
            this.targetGroup = targetGroup;
            return this;
        }

        public CustomerServiceBatchSending sendSubject(String sendSubject) {
            this.sendSubject = sendSubject;
            return this;
        }

        public CustomerServiceBatchSending createUser(String createUser) {
            this.createUser = createUser;
            return this;
        }

        public CustomerServiceBatchSending sender(String sender) {
            this.sender = sender;
            return this;
        }

        public CustomerServiceBatchSending mobile(String mobile) {
            this.mobile = mobile;
            return this;
        }
    }

}