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;

@Getter
@Setter
@Entity
@Table(name = "PROJECT_COST")
@ToString
public class ProjectCost 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 = "CONTRACT_ID")
    @ToString.Exclude
    private Contract contract;

    /**
     * 项目
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PROJECT_ID")
    @ToString.Exclude
    private Project project;

    @Column(name = "VER")
    private int version;

    /**
     * 是否标准付款方式
     */
    @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 = "STAMP_TAX")
    private float stampTax;

    /**
     * 印花税费用
     */
    @Column(name = "STAMP_TAX_FEE")
    private float stampTaxFee;

    /**
     * 现场服务费
     */
    @Column(name = "ON_SITE_SERVICE_FEE")
    private float onSiteServiceFee;

    /**
     * （拆）装机服务费
     */
    @Column(name = "ASSEMBLY_SERVICE_FEE")
    private float assemblyServiceFee;

    /**
     * 技术服务费
     */
    @Column(name = "TECHNICAL_SERVICE_FEE")
    private float technicalServiceFee;

    /**
     * 投标服务费
     */
    @Column(name = "BID_SERVICE_FEE")
    private float bidServiceFee;

    /**
     * 运费
     */
    @Column(name = "FREIGHT_COST")
    private float freightCost;

    /**
     * 保函费
     */
    @Column(name = "GUARANTEE_LETTER_FEE")
    private float guaranteeLetterFee;

    /**
     * 营业税及附加费
     * 0~100:0% ~ 100%
     */
    @Column(name = "TAX_AND_SURCHARGES")
    private float taxAndSurcharges;

    @Column(name = "TAX_AND_SURCHARGES_FEE")
    private float taxAndSurchargesFee;

    @Column(name = "IN_QUANTITY")
    private double inQuantities;

    /**
     * 含税进项总金额
     */
    @Column(name = "IN_TAX_AMOUNT")
    private double inTaxAmount;
    /**
     * 不含税进项总金额
     */
    @Column(name = "IN_EXCLUSIVE_TAX_AMOUNT")
    private double inExclusiveTaxAmount;

    @Column(name = "OUT_QUANTITY")
    private double outQuantities;
    /**
     * 含税出项总金额
     */
    @Column(name = "OUT_TAX_AMOUNT")
    private double outTaxAmount;
    /**
     * 不含税出项总金额
     */
    @Column(name = "OUT_EXCLUSIVE_TAX_AMOUNT")
    private double outExclusiveTaxAmount;

    /**
     * 毛利率
     */
    @Column(name = "GROSS_PROFIT_MARGIN")
    private double grossProfitMargin;
    /**
     * 申请人
     */
    @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 = "AUTHORIZER_FILE")
    private String authorizationFile;

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

    @Column(name = "IMPORT_LOCK")
    private boolean importLock;

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

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