package com.base.orbit.domain;

import com.base.orbit.domain.enity.SysMenu;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

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


/**
 * TreeMenu树结构实体类
 *
 * @author xj
 */

@Data
public class TreeMenu implements Serializable {

    private static final long serialVersionUID = 1L;

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

    /**
     * 菜单名称
     */
    private String menuName;

    /**
     * 菜单编号
     */
    private String menuCode;

    /**
     * 是否可用
     */
    private String status;

    /**
     * 菜单是否可见（默认不可见）
     */
    private boolean available = false;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createDate;

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


    public TreeMenu(SysMenu sysMenu) {
        this.id = sysMenu.getMenuId();
        this.menuName = sysMenu.getMenuName();
        this.menuCode=sysMenu.getMenuCode();
        this.status = sysMenu.getStatus().equals("0")?"正常":"停用";
        this.createDate = sysMenu.getCreateTime();
        this.children = sysMenu.getChildren().stream().map(TreeMenu::new).collect(Collectors.toList());

    }

    public TreeMenu() {
    }

    public Long getId() {
        return id;
    }

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

    public String getStatus() {
        return status;
    }

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

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getMenuName() {
        return menuName;
    }

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

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

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