package com.ecep.contract.model;

import java.io.Serializable;
import java.time.Instant;
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 jakarta.persistence.Version;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@Entity
@Table(name = "CLOUD_TYC", schema = "supplier_ms")
public class CloudTyc implements IdentityEntity, Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Integer id;

    /**
     * 评分
     */
    @ColumnDefault("0")
    @Column(name = "SCORE", nullable = false)
    private Integer score;

    @Column(name = "CLOUD_LATEST")
    private Instant cloudLatest;

    /**
     * 平台编号
     */
    @Column(name = "CLOUD_ID")
    private String cloudId;

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

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

    @Version
    @ColumnDefault("0")
    @Column(name = "VERSION", nullable = false)
    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;
        }
        CloudTyc cloudInfo = (CloudTyc) object;
        return getId() != null && Objects.equals(getId(), cloudInfo.getId());
    }

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

}