package com.ecep.contract.model;

import java.io.Serializable;
import java.time.LocalDateTime;
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_RK", schema = "supplier_ms")
public class CloudRk implements IdentityEntity, Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Integer id;

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

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

    /**
     * 是否自动更新
     */
    @Column(name = "AUTO_UPDATE", nullable = false, columnDefinition = "boolean default true")
    private boolean autoUpdate = false;

    /**
     * 更新间隔天数
     */
    @Column(name = "UPDATE_DAYS", nullable = false, columnDefinition = "int default 30")
    private int updateDays;

    /**
     * 客户信用评级
     */
    @ColumnDefault("''")
    @Column(name = "CUSTOMER_GRADE", nullable = false)
    private String customerGrade;
    /**
     * 客户信用总分
     */
    @ColumnDefault("0")
    @Column(name = "CUSTOMER_SCORE", nullable = false)
    private Integer customerScore;

    @Column(name = "CUSTOMER_DESCRIPTION")
    private String customerDescription;

    /**
     * 供应商信用评级
     */
    @ColumnDefault("''")
    @Column(name = "VENDOR_GRADE", nullable = false)
    private String vendorGrade;
    /**
     * 供应商信用总分
     */
    @ColumnDefault("0")
    @Column(name = "VENDOR_SCORE", nullable = false)
    private Integer vendorScore;

    @Column(name = "VENDOR_DESCRIPTION")
    private String vendorDescription;

    /**
     * 相关方资信评价等级
     */
    @ColumnDefault("''")
    @Column(name = "CREDIT_RANK", nullable = false)
    private String rank;
    /**
     * 相关方资信评价等级描述
     */
    @Column(name = "CREDIT_RANK_DESCRIPTION")
    private String rankDescription;
    /**
     * 云端最新更新时间
     */
    @Column(name = "CLOUD_LATEST")
    private LocalDateTime cloudLatest;
    /**
     * 黑名单更新时间
     */
    @Column(name = "BLACK_LIST_UPDATED")
    private LocalDateTime cloudBlackListUpdated;
    /**
     * 企业信息更新时间
     */
    @Column(name = "ENT_UPDATED")
    private LocalDateTime cloudEntUpdate;
    /**
     * 备注
     */
    @Column(name = "DESCRIPTION")
    private String description;
    /**
     * 本地更新时间戳，控制更新频率和重复更新
     */
    @Column(name = "LATEST_UPDATE")
    private LocalDateTime latestUpdate;
    /**
     * 版本号
     */
    @Column(name = "VERSION", nullable = false)
    private Integer version = 0;

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

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