package com.ecep.contract.model;

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

import com.ecep.contract.CompanyVendorFileType;
import com.ecep.contract.util.HibernateProxyUtils;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
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_FILE")
@ToString
public class CompanyVendorFile implements CompanyBasicFile<CompanyVendorFileType>, 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 = "VENDOR_ID")
    @ToString.Exclude
    private CompanyVendor vendor;

    @Column(name = "TYPE")
    @Enumerated(EnumType.STRING)
    private CompanyVendorFileType type;

    /**
     * 文件路径
     */
    @Column(name = "FILE_PATH")
    private String filePath;

    /**
     * 可编辑的文件路径
     */
    @Column(name = "EDIT_FILE_PATH")
    private String editFilePath;

    /**
     * 生效日期（签署）
     */
    @Column(name = "SIGN_DATE")
    private LocalDate signDate;

    @Column(name = "VALID")
    private boolean valid = false;

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

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