package cn.axzo.msg.center.message.domain.param;

import cn.axzo.core.utils.converter.BeanConverter;
import cn.axzo.msg.center.service.dto.IdentityDTO;
import cn.axzo.msg.center.service.dto.PersonDTO;
import cn.axzo.msg.center.service.enums.AppTerminalTypeEnum;
import cn.axzo.msg.center.service.pending.request.PendingMessageCountUncompletedRequest;
import cn.axzo.msg.center.service.pending.request.PendingMessageStatisticRequest;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @description
 *   消息分类统计功能的入参Param
 * @author cold_blade
 * @date 2023/9/26
 * @version 1.0
 */
@Setter
@Getter
public class MessageGroupNodeStatisticParam implements Serializable {

    private static final long serialVersionUID = 2301361555618643235L;

    /**
     * 当前登录账户的自然id(前端不care)
     */
    private PersonDTO operator;
    /**
     * 单位id
     */
    private Long ouId;
    /**
     * 应用终端类型
     */
    private AppTerminalTypeEnum terminalType;
    /**
     * 消息的分类结点编码集合
     */
    private Collection<String> groupNodeCodes;
    /**
     * 业务方是否只关注特定身份的消息
     *   true: 是
     *   false: 否
     */
    private Boolean withIdentify;
    /**
     * 项目部id列表
     */
    private List<Long> workspaceIds;

    public Long getPersonId() {
        return getOperator().getId();
    }

    public static MessageGroupNodeStatisticParam from(PendingMessageStatisticRequest request) {
        MessageGroupNodeStatisticParam param = BeanConverter.convert(request, MessageGroupNodeStatisticParam.class);
        IdentityDTO identity = IdentityDTO.builder()
                .id(request.getIdentityId())
                .type(request.getIdentityType())
                .build();
        PersonDTO person = PersonDTO.builder()
                .id(request.getPersonId())
                .identity(identity)
                .build();
        param.setOperator(person);
        param.setTerminalType(request.getTerminalType());
        return param;
    }

    public static MessageGroupNodeStatisticParam from(PendingMessageCountUncompletedRequest request) {
        MessageGroupNodeStatisticParam param = BeanConverter.convert(request, MessageGroupNodeStatisticParam.class);
        IdentityDTO identity = IdentityDTO.builder()
                .id(request.getIdentityId())
                .type(request.getIdentityType())
                .build();
        PersonDTO person = PersonDTO.builder()
                .id(request.getPersonId())
                .identity(identity)
                .build();
        param.setOperator(person);
        param.setTerminalType(request.getTerminalType());
        return param;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
