package com.ecep.contract.model;

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

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;

/**
 * 采购结算凭证
 * 对应 U8 的 PurSettleVouch 表
 */
@Getter
@Setter
@Entity
@Table(name = "PURCHASE_SETTLE_VOUCHER", schema = "supplier_ms")
@ToString
public class PurchaseSettlementVoucher implements IdentityEntity, BasedEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Integer id;

    /**
     * PurSettleVouch 表的 PSVID 主键
     */
    @Column(name = "REF_ID")
    private int refId;

    @Column(name = "CODE")
    private String code;
    /**
     * 对应 dSVDate 字段
     */
    @Column(name = "SETTLE_DATE")
    private LocalDate date;

    /**
     * 供应商，对应 cVenCode 字段
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "COMPANY_ID")
    @ToString.Exclude
    private Company company;

    /**
     * 业务员，对应 cPersonCode 字段
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "EMPLOYEE_ID")
    @ToString.Exclude
    private Employee employee;

    /**
     * 制单人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "MAKER_ID")
    @ToString.Exclude
    private Employee maker;

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

    @Override
    public String toPrettyString() {
        return "#" + getId();
    }

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

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