package cn.axzo.msg.center.service.dto;

import lombok.Getter;
import lombok.Setter;

import java.util.Objects;

/**
 * @author yanglin
 */
@Setter
@Getter
public class PeerPerson {

    public static PeerPerson nonPerson() {
        PeerPerson person = new PeerPerson();
        person.setPersonId(0L);
        person.setOuId(0L);
        person.setWorkspaceId(0L);
        return person;
    }

    public static PeerPerson withPersonIdOnly(Long personId) {
        PeerPerson person = new PeerPerson();
        person.setPersonId(personId);
        return person;
    }

    public static PeerPerson create(Long personId, Long ouId, Long workspaceId) {
        PeerPerson person = new PeerPerson();
        person.setPersonId(personId);
        person.setOuId(ouId);
        person.setWorkspaceId(workspaceId);
        return person;
    }

    /**
     * 自然人id
     */
    private Long personId = 0L;

    /**
     * 单位id
     */
    private Long ouId = 0L;

    /**
     * 项目id
     */
    private Long workspaceId = 0L;

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof PeerPerson)) return false;
        PeerPerson person = (PeerPerson) o;
        return Objects.equals(personId, person.personId) && Objects.equals(ouId, person.ouId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(personId, ouId);
    }

    public Long getPersonIdOrDefault() {
        return personId == null ? 0L : personId;
    }

    public Long getOuIdOrDefault() {
        return ouId == null ? 0L : ouId;
    }

    public Long getWorkspaceIdOrDefault() {
        return workspaceId == null ? 0L : workspaceId;
    }
}