package com.ecep.contract.model;

import java.util.Objects;

import com.ecep.contract.ContractFileType;
import com.ecep.contract.util.HibernateProxyUtils;

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 = "PROJECT_SALE_TYPE_REQ_FILE_TYPE")
public class ProjectSaleTypeRequireFileType implements IdentityEntity, BasedEntity {
    @Id
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SALE_TYPE_ID")
    @ToString.Exclude
    private ProjectSaleType saleType;

    @Column(name = "FILE_TYPE")
    @Enumerated(EnumType.STRING)
    private ContractFileType fileType;

    /**
     * 文件频率，如：一次、每天、每周、每月、每季度、每年等
     */
    @Column(name = "FREQUENCY")
    @Enumerated(EnumType.STRING)
    private ContractFileType.Frequency frequency;

    @Override
    public String toPrettyString() {
        return getFileType().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;
        }
        ProjectSaleTypeRequireFileType that = (ProjectSaleTypeRequireFileType) object;
        return getId() != null && Objects.equals(getId(), that.getId());
    }

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