package com.qmth.paper.library.common.entity;

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.paper.library.common.base.BaseEntity;
import com.qmth.paper.library.common.contant.SystemConstant;
import com.qmth.paper.library.common.enums.OrgTypeEnum;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Objects;

/**
 * <p>
 * 学校组织架构
 * </p>
 *
 * @author xf
 * @since 2021-03-23
 */
@TableName("sys_org")
public class SysOrg extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "学校id")
    @JsonSerialize(using = ToStringSerializer.class)
    @TableField("school_id")
    private Long schoolId;

    /**
     * 机构代码
     */
    private String code;

    @ApiModelProperty(value = "类型，COLLEGE：学院，FACULTY：院系，TEACHING_ROOM：教研室，PRINTING_HOUSE：印刷厂")
    @TableField(value = "type", updateStrategy = FieldStrategy.IGNORED)
    private OrgTypeEnum type;

    /**
     * 机构名称
     */
    @NotBlank(message = "机构名称不能为空")
    private String name;
    /**
     * 上级机构ID
     */
    @JsonSerialize(using = ToStringSerializer.class)
    @TableField("parent_id")
    private Long parentId;

    @ApiModelProperty(value = "是否启用，0：停用，1：启用")
    private Boolean enable;

    @ApiModelProperty("历史机构名")
    private String historicName;

    public SysOrg() {

    }

    public SysOrg(Long schoolId, String name) {
        setId(SystemConstant.getDbUuid());
        this.schoolId = schoolId;
        this.type = OrgTypeEnum.SCHOOL;
        this.name = name;
        this.enable = true;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        SysOrg sysOrg = (SysOrg) o;
        return schoolId.equals(sysOrg.schoolId) && code.equals(sysOrg.code) && type == sysOrg.type && name.equals(sysOrg.name) && parentId.equals(sysOrg.parentId) && enable.equals(sysOrg.enable) && historicName.equals(sysOrg.historicName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(schoolId, code, type, name, parentId, enable, historicName);
    }

    public String getHistoricName() {
        return historicName;
    }

    public void setHistoricName(String historicName) {
        this.historicName = historicName;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public OrgTypeEnum getType() {
        return type;
    }

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

    public Long getSchoolId() {
        return schoolId;
    }

    public void setSchoolId(Long schoolId) {
        this.schoolId = schoolId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getParentId() {
        return parentId;
    }

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

    public Boolean getEnable() {
        return enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }
}
