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

import java.time.LocalDate;
import java.util.Objects;

import com.ecep.contract.CompanyFileType;
import com.ecep.contract.model.IdentityEntity;
import com.ecep.contract.model.Voable;
import com.ecep.contract.util.HibernateProxyUtils;
import com.ecep.contract.vo.CompanyFileVo;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
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_FILE")
@ToString
public class CompanyFile implements IdentityEntity, CompanyBasedEntity, Voable<CompanyFileVo> {

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

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

    @Column(name = "TYPE")
    @Enumerated(EnumType.STRING)
    private CompanyFileType type;

    /**
     * 生效日期（签署）
     */
    @Column(name = "APPLY_DATE")
    private LocalDate applyDate;
    /**
     * 有效期（签署）
     */
    @Column(name = "EXP_DATE")
    private LocalDate expiringDate;

    /**
     * 资质文件路径，全路径，网盘地址
     */
    @Column(name = "FILE_PATH")
    private String filePath;

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

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

    @Override
    public CompanyFileVo toVo() {
        CompanyFileVo vo = new CompanyFileVo();
        vo.setId(id);
        if (company != null) {
            vo.setCompanyId(company.getId());
        }
        vo.setType(type);
        vo.setApplyDate(applyDate);
        vo.setExpiringDate(expiringDate);
        vo.setFilePath(filePath);
        vo.setActive(false); // 实体类中没有active字段，设置默认值false
        return vo;
    }
}
