package com.storlead.user.model;

import com.storlead.user.pojo.entity.DeptEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 部门表 存储树结构数据的实体类
 * <p>
 *
 * @Author Steve
 * @Since 2019-01-22
 */
@ApiModel(value="部门tree对象", description="部门tree对象详细信息")
public class DeptTreeModel implements Serializable {

    private static final long serialVersionUID = 1L;

    /** 对应SysDepart中的id字段,前端数据树中的key*/
    @ApiModelProperty(value = "对应dept中的id字段,前端数据树中的key")
    private String key;

    /** 对应SysDepart中的id字段,前端数据树中的value*/
    @ApiModelProperty(value = "对应dept中的id字段,前端数据树中的value")
    private String value;

    /** 对应depart_name字段,前端数据树中的title*/
    @ApiModelProperty(value = "对应dept中的name字段,前端数据树中的title")
    private String title;

    @ApiModelProperty(value = "部门名称")
    private String name;

    @ApiModelProperty(value = "排序")
    private Integer sort;

    @ApiModelProperty(value = "分公司ID")
    private Long subCompanyId;

    private boolean isLeaf;
    // 以下所有字段均与SysDepart相同

    @ApiModelProperty(value = "部门ID")
    private Long id;

    @ApiModelProperty(value = "上级部门ID")
    private Long pid;

    @ApiModelProperty(value = "是否启用(1：启用 2：禁用）")
    private Integer enabled;

    private List<DeptTreeModel> children = new ArrayList<>();


    /**
     * 将SysDepart对象转换成SysDepartTreeModel对象
     * @param dept
     */
	public DeptTreeModel(DeptEntity dept) {
		this.key = String.valueOf(dept.getId());
        this.value = String.valueOf(dept.getId());
        this.title = dept.getName();
        this.id = dept.getId();
        this.pid = dept.getPid();
        this.enabled = dept.getEnabled() ? 1 : 0;
        this.name = dept.getName();
        this.sort = dept.getSort();
        this.subCompanyId = dept.getSubCompanyId();
    }

    public boolean getIsLeaf() {
        return isLeaf;
    }

    public void setIsLeaf(boolean isleaf) {
         this.isLeaf = isleaf;
    }

    public String getKey() {
		return key;
	}


	public void setKey(String key) {
		this.key = key;
	}


    public String getName() {
        return name;
    }

    public Integer getSort() {
        return sort;
    }

    public Long getSubCompanyId() {
        return subCompanyId;
    }

    public Long getPid() {
        return pid;
    }

    public Integer getEnabled() {
        return enabled;
    }

    public String getValue() {
		return value;
	}


	public void setValue(String value) {
		this.value = value;
	}


	public String getTitle() {
		return title;
	}


	public void setTitle(String title) {
		this.title = title;
	}


	public Long getId() {
        return id;
    }

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

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

    public void setChildren(List<DeptTreeModel> children) {
        if (children==null){
            this.isLeaf=true;
        }
        this.children = children;
    }

    public DeptTreeModel() { }

    /**
     * 重写equals方法
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) {
			return true;
		}
        if (o == null || getClass() != o.getClass()) {
			return false;
		}
        DeptTreeModel model = (DeptTreeModel) o;
        return Objects.equals(id, model.id) &&
                Objects.equals(pid, model.pid) &&
                Objects.equals(sort, model.sort) &&
                Objects.equals(name, model.name) &&
                Objects.equals(subCompanyId, subCompanyId) &&
                Objects.equals(enabled, enabled) &&
                Objects.equals(children, model.children);
    }

    /**
     * 重写hashCode方法
     */
    @Override
    public int hashCode() {

        return Objects.hash(id, pid, sort, name, subCompanyId, enabled,
        		children);
    }

}
