package com.ecep.contract.model;

import java.io.Serializable;
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;

@Getter
@Setter
@Entity
@Table(name = "PROJECT_COST_ITEM")
@ToString
public class ProjectCostItem implements IdentityEntity, BasedEntity, 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 = "COST_ID")
    @ToString.Exclude
    private ProjectCost cost;

    /**
     * 项目
     */
    @Column(name = "TITLE")
    private String title;

    /**
     * 规格
     */
    @Column(name = "SPECIFICATION")
    private String specification;

    /**
     * 单位
     */
    @Column(name = "UNIT")
    private String unit;

    /**
     * 存货
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "INVENTORY_ID")
    @ToString.Exclude
    private Inventory inventory;

    /**
     * 进项税率
     */
    @Column(name = "IN_TAX_RATE")
    private double inTaxRate;

    /**
     * 进项不含税单价
     */
    @Column(name = "IN_TAX_PRICE")
    private double inExclusiveTaxPrice;

    /**
     * 进项数量
     */
    @Column(name = "IN_QUANTITY")
    private double inQuantity;


    /**
     * 出项税率
     */
    @Column(name = "OUT_TAX_RATE")
    private double outTaxRate;

    /**
     * 出项不含税单价
     */
    @Column(name = "OUT_TAX_PRICE")
    private double outExclusiveTaxPrice;

    /**
     * 出项数量
     */
    @Column(name = "OUT_QUANTITY")
    private double outQuantity;

    /**
     * 备注
     */
    @Column(name = "REMARK")
    private String remark;

    /**
     * 创建日期
     */
    @Column(name = "CREATE_TIME")
    private LocalDateTime createDate;
    /**
     * 创建人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CREATE_BY")
    @ToString.Exclude
    private Employee creator;

    /**
     * 更新日期
     */
    @Column(name = "UPDATE_TIME")
    private LocalDateTime updateDate;
    /**
     * 更新人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "UPDATE_BY")
    @ToString.Exclude
    private Employee updater;

    @Override
    public String toPrettyString() {
        return getTitle() + " " + getSpecification();
    }

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

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