package easydo.technology.system.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import easydo.technology.base.CommonDto;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 * @author jinjin
 * @date 2020-09-25
 */
@Getter
@Setter
@NoArgsConstructor
public class DeptDto extends CommonDto {
    private static final long serialVersionUID = 1L;

    private Long id;

    private Long pid;

    private Integer subCount;

    private String name;

    private Integer deptSort;

    private String firmType;

    private String firmCredit;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime firmTime;

    private String firmAddress;

    private String firmCapital;

    private String firmNature;

    private String firmLegalPerson;

    private String firmLegalPersonPhone;

    private String firmFunctionary;

    private String firmFunctionaryPhone;

    private String firmOfficePhone;

    private String firmFaxNumber;

    private String firmBusinessAddress;

    private String remark;

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<DeptDto> children;

    private Boolean enabled;

    public Boolean getHasChildren() {
        return subCount > 0;
    }

    public Boolean getLeaf() {
        return subCount <= 0;
    }

    public String getLabel() {
        return name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        DeptDto deptDto = (DeptDto) o;
        return Objects.equals(id, deptDto.id) &&
                Objects.equals(name, deptDto.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }
}
