package cn.axzo.msg.center.service.group.response;

import cn.axzo.msg.center.service.enums.MessageGroupNodeCategoryEnum;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.collections.CollectionUtils;

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

/**
 * @author cold_blade
 * @date 2023/10/12
 * @version 1.0
 */
@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MessageGroupTreeNodeResponse implements Serializable {

    private static final long serialVersionUID = -6741888813327778598L;

    /**
     * 结点类型
     *     GENERAL_MESSAGE_CENTER: 消息中心
     *     GENERAL_MESSAGE_MODULE: 消息模块
     *     GENERAL_MESSAGE_CATEGORY: 消息分类
     *     PENDING_MESSAGE_CENTER: 待办中心
     *     PENDING_MESSAGE_MODULE: 待办模块
     *     PENDING_MESSAGE_CATEGORY: 待办分类
     */
    private MessageGroupNodeCategoryEnum category;
    /**
     * 结点名称
     */
    private String nodeName;
    /**
     * 结点编码
     */
    private String nodeCode;
    /**
     * 父节点编码
     */
    private String parentNodeCode;
    /**
     * 结点图标
     */
    private String nodeIcon;
    /**
     * 子节点列表
     */
    private List<MessageGroupTreeNodeResponse> children;

    public void addChild(MessageGroupTreeNodeResponse treeNode) {
        if (CollectionUtils.isEmpty(children)) {
            children = Lists.newArrayList();
        }
        children.add(treeNode);
        treeNode.setParentNodeCode(this.nodeCode);
    }

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