package com.ecep.contract.model;

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

import org.hibernate.annotations.ColumnDefault;

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;

/**
 * 项目投标
 * <p>
 * Approval 审批
 */
@Getter
@Setter
@Entity
@Table(name = "PROJECT_BID")
@ToString
public class ProjectBid implements IdentityEntity, ProjectBasedEntity, 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 = "PROJECT_ID")
    @ToString.Exclude
    private Project project;
    /**
     * 客户资信等级
     */
    @Column(name = "LEVEL", nullable = false)
    private int level;
    /**
     * 报价金额
     */
    @Column(name = "AMOUNT")
    private double amount;

    /**
     * 评价表单文件
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CUS_EVAL_FILE_ID")
    @ToString.Exclude
    private CompanyCustomerEvaluationFormFile evaluationFile;

    /**
     * 成本
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "COST_ID")
    @ToString.Exclude
    private ProjectCost cost;

    /**
     * 是否标准付款方式
     */
    @ColumnDefault("0")
    @Column(name = "STANDARD_PAY_WAY", nullable = false)
    private boolean standardPayWay;
    /**
     * 非标准付款方式文本
     */
    @Column(name = "NO_STANDARD_PAY_WAY_TEXT")
    private String noStandardPayWayText;

    /**
     * 是否标准合同文本
     */
    @ColumnDefault("0")
    @Column(name = "STANDARD_CONTRACT_TEXT", nullable = false)
    private boolean standardContractText;
    /**
     * 非标准合同文本
     */
    @Column(name = "NO_STANDARD_CONTRACT_TEXT")
    private String noStandardContractText;

    /**
     * 审核文件
     */
    @Column(name = "AUTHORIZER_FILE")
    private String authorizationFile;

    /**
     * 中标通知书文件
     */
    @Column(name = "BID_ACCEPTANCE_LETTER_FILE")
    private String bidAcceptanceLetterFile;

    /**
     * 申请人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "APPLICANT_ID")
    @ToString.Exclude
    private Employee applicant;
    /**
     * 申请日期
     */
    @Column(name = "APPLY_DATE")
    private LocalDateTime applyTime;
    /**
     * 审核人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "AUTHORIZER_ID")
    @ToString.Exclude
    private Employee authorizer;
    /**
     * 审核时间
     */
    @Column(name = "AUTHORIZER_DATE")
    private LocalDateTime authorizationTime;

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

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

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