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 的 SO_SOMain 表
 */
@Getter
@Setter
@Entity
@Table(name = "CONTRACT_SALES_ORDER", schema = "supplier_ms")
@ToString
public class SalesOrder 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;

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

    /**
     * 制单日期
     */
    @Column(name = "MAKER_DATE")
    private LocalDate makerDate;
    /**
     * 审核人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "VERIFIER_ID")
    @ToString.Exclude
    private Employee verifier;
    /**
     * 审核日期
     */
    @Column(name = "VERIFIER_DATE")
    private LocalDate verifierDate;
    /**
     * 备注
     */
    @Column(name = "DESCRIPTION", columnDefinition = "TEXT")
    private String description;

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

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

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