package com.ecep.contract.model;

import com.ecep.contract.util.HibernateProxyUtils;
import com.ecep.contract.vo.VendorGroupVo;
import com.ecep.contract.model.Voable;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

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

/**
 * 采购合同类型
 */
@Getter
@Setter
@Entity
@Table(name = "VENDOR_GROUP", schema = "supplier_ms")
@ToString
public class VendorGroup implements IdentityEntity, NamedEntity, BasedEntity, Serializable, Voable<VendorGroupVo> {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "NAME")
    private String name;

    @Column(name = "CODE")
    private String code;

    @Column(name = "DESCRIPTION", columnDefinition = "TEXT")
    private String description;

    @Column(name = "IS_ACTIVE")
    private boolean active;

    @Column(name = "IS_PRICE_COMP")
    private boolean priceComparison;

    /**
     * 中选的供应商是否可以免除报价表
     */
    @Column(name = "IS_REQUIRE_QUOTATION_SHEET_FOR_BID")
    private boolean requireQuotationSheetForBid;

    /**
     * 是否可以提前预采购
     */
    @Column(name = "CAN_PRE_PURCHASE")
    private boolean canPrePurchase;

    @Override
    public String toPrettyString() {
        return code + " " + name;
    }

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

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

    @Override
    public VendorGroupVo toVo() {
        VendorGroupVo vo = new VendorGroupVo();
        vo.setId(id);
        vo.setName(name);
        vo.setCode(code);
        vo.setDescription(description);
        vo.setActive(active);
        vo.setPriceComparison(priceComparison);
        vo.setRequireQuotationSheetForBid(requireQuotationSheetForBid);
        vo.setCanPrePurchase(canPrePurchase);
        // path字段在VendorGroup中没有对应字段，设置为null
        vo.setPath(null);
        // version字段在VendorGroup中没有对应字段，设置为0
        vo.setVersion(0);
        return vo;
    }
}
