package com.ecep.contract.ds.company.model;

import java.time.LocalDate;
import java.util.Objects;

import com.ecep.contract.model.IdentityEntity;
import com.ecep.contract.model.NamedEntity;
import com.ecep.contract.model.Voable;
import org.hibernate.annotations.ColumnDefault;

import com.ecep.contract.util.HibernateProxyUtils;
import com.ecep.contract.vo.CompanyOldNameVo;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@Entity
@Table(name = "COMPANY_OLDNAME")
@ToString
public class CompanyOldName implements IdentityEntity, NamedEntity, Voable<CompanyOldNameVo> {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Integer id;

    @Column(name = "COMPANY_ID", nullable = false)
    private Integer companyId;

    @Column(name = "NAME")
    private String name;

    @Column(name = "BEGIN_DATE")
    private LocalDate beginDate;

    @Column(name = "END_DATE")
    private LocalDate endDate;

    /**
     * 是否模糊的，当已录入的系统的名称有错误时，使用别名处理
     */
    @Column(name = "AMBIGUITY")
    private Boolean ambiguity;

    @Column(name = "PATH")
    private String path;

    @Column(name = "MEMO")
    @ToString.Exclude
    private String memo;

    @Version
    @ColumnDefault("0")
    @Column(name = "VERSION", nullable = false)
    @ToString.Exclude
    private int version;

    @Override
    public final boolean equals(Object object) {
        if (this == object)
            return true;
        if (object == null)
            return false;
        if (HibernateProxyUtils.isNotEffectiveClassEquals(object, this)) {
            return false;
        }
        CompanyOldName that = (CompanyOldName) object;
        return getId() != null && Objects.equals(getId(), that.getId());
    }

    @Override
    public final int hashCode() {
        return HibernateProxyUtils.hashCode(this);
    }

    @Override
    public CompanyOldNameVo toVo() {
        CompanyOldNameVo vo = new CompanyOldNameVo();
        vo.setId(id);
        vo.setCompanyId(companyId);
        vo.setName(name);
        vo.setBeginDate(beginDate);
        vo.setEndDate(endDate);
        vo.setAmbiguity(ambiguity);
        vo.setPath(path);
        vo.setMemo(memo);
        vo.setVersion(version);
        return vo;
    }
}