package com.dcsoft.system.domain.vo;

import com.dcsoft.system.domain.SysPoint;
import com.dcsoft.system.domain.SysSpace;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.NoArgsConstructor;

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


/**
 * 权限对象 通用结构
 *
 * @author xueyi
 */
@Data
@NoArgsConstructor
public class SysAuthTree  {


    /** Id */
    private Long id;

    /** 父级Id */
    private Long parentId;

    /** 名称 */
    private String label;

    /** 状态 */
    private String status;

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

    /** 类型（0 模块 1 菜单） */
    private String type;

    private String deviceId;

    private String channelId;

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getChannelId() {
        return channelId;
    }

    public void setChannelId(String channelId) {
        this.channelId = channelId;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public List<SysAuthTree> getChildren() {
        return children;
    }

    public void setChildren(List<SysAuthTree> children) {
        this.children = children;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    /**
     * 模块转换
     */
    public SysAuthTree(SysSpace module) {
        this.id = module.getId();
        this.label = module.getName();
        this.type = "0";
        this.children = module.getChildren().stream().map(SysAuthTree::new).collect(Collectors.toList());
        this.children.addAll(module.getChildren1().stream().map(SysAuthTree::new).collect(Collectors.toList()));
    }

    /**
     * 菜单转换
     */
    public SysAuthTree(SysPoint point) {
        this.id = point.getId();
        this.label = point.getName();
        this.type = "1";

    }
}
