package com.ecep.contract.ds.company.model;

import java.util.Objects;

import com.ecep.contract.model.BasedEntity;
import com.ecep.contract.model.IdentityEntity;
import com.ecep.contract.model.NamedEntity;
import com.ecep.contract.model.Voable;
import com.ecep.contract.util.HibernateProxyUtils;
import com.ecep.contract.vo.CompanyInvoiceInfoVo;

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, Voable<CompanyInvoiceInfoVo> {

    @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);
    }

    @Override
    public CompanyInvoiceInfoVo toVo() {
        CompanyInvoiceInfoVo vo = new CompanyInvoiceInfoVo();
        vo.setId(id);
        vo.setName(name);
        if (company != null) {
            vo.setCompanyId(company.getId());
        }
        vo.setTaxId(taxId);
        vo.setAddress(address);
        vo.setPhone(phone);
        vo.setBankName(bankName);
        vo.setBankAccount(bankAccount);
        return vo;
    }
}
