package com.chinaweal.aiccs.common.base.entity;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 树节点
 *
 * @author <a href="https://blog.lroyia.top">lroyia</a>
 * @since 2020/8/11 10:41
 **/
@Data
public class TreeNode {

    /**
     * 父节点id（选用）
     */
    private String pId;

    /**
     * 节点名称
     */
    private String name;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 节点值
     */
    private String value;
    /**
     * 备注信息
     */
    private String remark;

    /**
     * 子节点
     */
    private List<TreeNode> children;

    public TreeNode(String name, String value) {
        super();
        this.name = name;
        this.label = name;
        this.value = value;
        this.children = new ArrayList<>();
    }

    public TreeNode(String pId, String name, String value) {
        super();
        this.name = name;
        this.label = name;
        this.value = value;
        this.pId = pId;
        this.children = new ArrayList<>();
    }

    public TreeNode(String pId, String name, String value, String remark) {
        super();
        this.name = name;
        this.label = name;
        this.value = value;
        this.pId = pId;
        this.remark = remark;
        this.children = new ArrayList<>();
    }

    /**
     * 添加子节点
     *
     * @param node 节点信息
     * @return 当前节点
     */
    public TreeNode addChild(TreeNode node) {
        if (node != null) {
            children.add(node);
        }
        return this;
    }
}
