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

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

import com.ecep.contract.CustomerFileType;
import com.ecep.contract.model.CompanyBasicFile;
import com.ecep.contract.model.Voable;
import com.ecep.contract.util.HibernateProxyUtils;
import com.ecep.contract.vo.CustomerFileVo;

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_CUSTOMER_FILE")
@ToString
public class CompanyCustomerFile implements CompanyBasicFile<CustomerFileType>, Voable<CustomerFileVo> {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Integer id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CUSTOMER_ID")
    @ToString.Exclude
    private CompanyCustomer customer;

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

    /**
     * 文件路径
     */
    @Column(name = "FILE_PATH")
    private String filePath;

    /**
     * 可编辑的文件路径
     */
    @Column(name = "EDIT_FILE_PATH")
    private String editFilePath;

    /**
     * 生效日期（签署）
     */
    @Column(name = "SIGN_DATE")
    private LocalDate signDate;

    @Column(name = "VALID")
    private boolean valid = false;

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

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

    @Override
    public CustomerFileVo toVo() {
        CustomerFileVo vo = new CustomerFileVo();
        vo.setId(getId());
        vo.setCustomer(getCustomer() != null ? getCustomer().getId() : null);
        vo.setType(getType());
        vo.setFilePath(getFilePath());
        vo.setEditFilePath(getEditFilePath());
        vo.setSignDate(getSignDate());
        vo.setValid(isValid());
        return vo;
    }
}
