package com.ecep.contract.model;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Objects;

import com.ecep.contract.util.HibernateProxyUtils;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@Entity
@Table(name = "COMPANY_CUSTOMER_ENTITY", schema = "supplier_ms", indexes = {

})
@ToString
public class CompanyCustomerEntity implements IdentityEntity, Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "COMPANY_CUSTOMER_ID")
    @ToString.Exclude
    private CompanyCustomer customer;

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

    @Column(name = "ABB_NAME")
    private String abbName;
    /**
     * 用友U8系统中的客户编号,1对多的原因使用编码 |code1|code2|
     */
    @Column(name = "CUS_CODE")
    private String code;

    /**
     * 客户分类
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CUS_CLS")
    @ToString.Exclude
    private CustomerCatalog catalog;

    /**
     * 创建人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CREATOR_ID")
    @ToString.Exclude
    private Employee creator;

    /**
     * 修改人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "MODIFIER_ID")
    @ToString.Exclude
    private Employee modifier;

    /**
     * 修改日期
     */
    @Column(name = "MODIFY_DATE")
    private LocalDate modifyDate;
    /**
     * 发展日期
     */
    @Column(name = "DEV_DATE")
    private LocalDate developDate;

    /**
     * 更新日期，有数据更新时的日期
     */
    @Column(name = "UP_DATE")
    private LocalDate updatedDate;
    /**
     * 抓取时间戳，用于控制抓取频率
     */
    @Column(name = "FETCHED_TIME")
    private LocalDateTime fetchedTime;

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

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