package com.ecep.contract.model;

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

import com.ecep.contract.ContractPayWay;
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;

/**
 * 项目投标
 * <p>
 * Approval 审批
 */
@Getter
@Setter
@Entity
@Table(name = "PROJECT_FUND_PLAN")
@ToString
public class ProjectFundPlan implements IdentityEntity, ProjectBasedEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Integer id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PROJECT_ID")
    private Project project;
    /**
     * 付款日期
     */
    @Column(name = "PAY_DATE")
    private LocalDate payDate;
    /**
     * 付款方式
     */
    @Column(name = "PAY_WAY")
    @Enumerated(EnumType.ORDINAL)
    private ContractPayWay payWay;
    /**
     * 付款比例
     */
    @Column(name = "PAY_RATIO")
    private float payRatio;
    /**
     * 付款金额
     */
    @Column(name = "PAY_CURRENCY")
    private double payCurrency;
    /**
     * 付款条件
     */
    @Column(name = "PAY_TERM")
    private String payTerm;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CONTRACT_PAY_PLAN_ID")
    private ContractPayPlan contractPayPlan;

    /**
     * 更新日期，从销售合同和采购合同中更新
     */
    @Column(name = "UPDATE_TIME")
    private LocalDateTime updateDate;

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

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