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

import cn.axzo.msg.center.service.pending.response.PendingMessageStatisticResponse;
import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

/**
 * @description
 *   消息分类结点DTO
 *
 * @author cold_blade
 * @date 2023/9/26
 * @version 1.0
 */
@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PendingMessageStatisticDTO implements Serializable {

    private static final long serialVersionUID = 5171436359992401120L;

    /**
     * 叶结点编码
     */
    private String leafNodeCode;
    /**
     * 叶节点名称
     */
    private String leafNodeName;
    /**
     * 结点对应的代办数量
     */
    private Integer pendingCount;

    public static PendingMessageStatisticDTO of(GroupTreeNodePathDTO groupNode) {
        return PendingMessageStatisticDTO.builder()
                .leafNodeName(groupNode.getNodeName())
                .leafNodeCode(groupNode.getNodeCode())
                .build();
    }

    public PendingMessageStatisticResponse toResponse() {
        PendingMessageStatisticResponse response = new PendingMessageStatisticResponse();
        response.setGroupCode(this.leafNodeCode);
        response.setGroupName(this.leafNodeName);
        response.setPendingCount(this.pendingCount);
        return response;
    }

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