package com.ecep.contract.model;

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

import org.hibernate.annotations.ColumnDefault;

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 = "CLOUD_YU", schema = "supplier_ms")
@ToString
public class CloudYu implements IdentityEntity, Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Integer id;

    /**
     * 本地更新时间戳，控制更新频率和重复更新
     */
    @Column(name = "LATEST_UPDATE")
    private Instant latestUpdate;

    /**
     * 关联的公司
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "COMPANY_ID")
    @ToString.Exclude
    private Company company;

    @ColumnDefault("''")
    @Column(name = "EX_MSG")
    private String exceptionMessage;

    /**
     * 供应商信息更新日期
     */
    @Column(name = "VEN_UP_DATE")
    private LocalDate vendorUpdateDate;

    /**
     * 客户信息更新日期
     */
    @Column(name = "CUS_UP_DATE")
    private LocalDate customerUpdateDate;

    /**
     * 数据更新日期
     */
    @Column(name = "CLOUD_LATEST")
    private Instant cloudLatest;

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

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