package com.vctgo.system.domain.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.vctgo.system.api.domain.SysDept;
import com.vctgo.system.api.domain.SysPlatformDept;
import com.vctgo.system.domain.SysMenu;
import com.vctgo.system.domain.SysPlatformMenu;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 *
 * @author vctgo
 */
@Data
@NoArgsConstructor
public class TreeSelect implements Serializable
{
    private static final long serialVersionUID = 1L;

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

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

    /** 租户ID */
    private Long tenantId;

    /** 租户ID */
    private String deptType;

    /**
     * 显示顺序
     */
    private Integer orderNum;

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

    public TreeSelect(SysDept dept)
    {
        this.id = dept.getDeptId();
        this.label = dept.getDeptName();
        this.tenantId = dept.getTenantId();
        this.deptType = dept.getDeptType();
        this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysPlatformDept dept)
    {
        this.id = dept.getDeptId();
        this.label = dept.getDeptName();
        this.tenantId = dept.getTenantId();
        this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysMenu menu)
    {
        this.id = menu.getMenuId();
        this.label = menu.getMenuName();
        this.tenantId = menu.getTenantId();
        this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        this.orderNum = menu.getOrderNum();
    }

    public TreeSelect(SysPlatformMenu menu)
    {
        this.id = menu.getMenuId();
        this.label = menu.getMenuName();
        this.tenantId = menu.getTenantId();
        this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

}
