package com.ecep.contract.model;

import java.time.LocalDateTime;
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 的 PO_Pomain 表
 */
@Getter
@Setter
@Entity
@Table(name = "PURCHASE_ORDER", schema = "supplier_ms")
@ToString
public class PurchaseOrder implements IdentityEntity, BasedEntity, ContractBasedEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Integer id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CONTRACT_ID")
    @ToString.Exclude
    private Contract contract;
    /**
     * 业务员
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "EMPLOYEE_ID")
    @ToString.Exclude
    private Employee employee;

    @Column(name = "CODE")
    private String code;

    @Column(name = "REF_ID")
    private int refId;

    @Column(name = "VEN_CODE")
    private String vendorCode;
    /**
     * 制单人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "MAKER_ID")
    @ToString.Exclude
    private Employee maker;
    /**
     * 制单日期
     */
    @Column(name = "MAKER_DATE")
    private LocalDateTime makerDate;
    /**
     * 修改日期
     */
    @Column(name = "MODIFY_DATE")
    private LocalDateTime modifyDate;
    /**
     * 审核人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "VERIFIER_ID")
    @ToString.Exclude
    private Employee verifier;
    /**
     * 审核日期
     */
    @Column(name = "VERIFIER_DATE")
    private LocalDateTime verifierDate;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CLOSER_ID")
    @ToString.Exclude
    private Employee closer;
    @Column(name = "CLOSER_DATE")
    private LocalDateTime closerDate;

    @Column(name = "DESCRIPTION", columnDefinition = "TEXT")
    private String description;

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

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

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