package com.ecep.contract.model;

import java.io.Serializable;
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 = "COMPANY_INVOICE_INFO", schema = "supplier_ms")
@ToString
public class CompanyInvoiceInfo implements IdentityEntity, NamedEntity, BasedEntity, CompanyBasedEntity, Serializable {
    private static final long serialVersionUID = 1L;

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

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

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "COMPANY_ID")
    @ToString.Exclude
    private Company company;

    @Column(name = "TAX")
    private String taxId; // 税号（纳税人识别号）

    @Column(name = "ADDR")
    private String address; // 地址

    @Column(name = "TEL")
    private String phone; // 电话

    @Column(name = "BANK")
    private String bankName; // 开户行

    @Column(name = "BANK_ACCOUNT")
    private String bankAccount; // 银行账号

    @Override
    public String toPrettyString() {
        return getName() + getTaxId();
    }

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

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