package com.microservices.pms.product.domain.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.microservices.pms.product.domain.PmsProductModule;
import lombok.Data;

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

/**
 * @author otto
 */
@Data
public class TreeSelect implements Serializable {
    private static final long serialVersionUID = 1L;

    /** 节点ID */
    private Long id;
    /** 父节点ID */
    private Long parentId;

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

    /** 节点数据 */
    private Object data;

    /** 是否为叶子结点 */
    private Boolean isLeaf;

    /** 层级 */
    private Integer level;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect()
    {

    }

    public TreeSelect(PmsProductModule pmsProductModule,int level)
    {
        this.level=level;
        this.parentId = pmsProductModule.getParentId();
        this.id = pmsProductModule.getId();
        this.label = pmsProductModule.getModuleName();
        this.data = pmsProductModule.getNodeDataCount();

        this.children = pmsProductModule.getChildren().stream().map(x->new TreeSelect(x,this.level+1)).collect(Collectors.toList());
        this.isLeaf= this.children.isEmpty();
    }
}
