package com.ecep.contract.model;

import java.io.Serializable;
import java.util.Objects;

import com.ecep.contract.VendorType;
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_VENDOR_APPROVED_ITEM")
@ToString
public class CompanyVendorApprovedItem implements IdentityEntity, Serializable {
    private static final long serialVersionUID = 1L;

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

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "LIST_ID", nullable = false)
    @ToString.Exclude
    private CompanyVendorApprovedList list;

    /**
     * 供应商名称，有可能改名了，所以存历史名称
     */
    @Column(name = "VENDOR_NAME")
    private String vendorName;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "VENDOR_ID", nullable = false)
    @ToString.Exclude
    private CompanyVendor vendor;

    /**
     * 类型，历史的，可能会变更的，所以这样也要存
     */
    @Column(name = "TYPE")
    private VendorType type;

    /**
     * 备注
     */
    @Column(name = "DESCRIPTION")
    private String description;

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

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