package com.ecep.contract.model;

import java.time.LocalDate;
import java.time.LocalDateTime;
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 = "PROJECT_CUSTOMER_SATISFACTION_SURVEY", schema = "supplier_ms")
@ToString
public class CustomerSatisfactionSurvey implements IdentityEntity, ProjectBasedEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Integer id;

    /**
     * 项目
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PROJECT_ID")
    @ToString.Exclude
    private Project project;

    @Column(name = "CODE", length = 100)
    private String code;

    @Column(name = "DATE")
    private LocalDate date;

    /**
     * 总分
     */
    @Column(name = "TOTAL_SCORE")
    private int totalScore;
    /**
     * 数据，格式如下
     * version:a,b,c,d,e,f,g,h,i,j
     * version 表示项目版本号，不同的版本号表示不同的项目，a-j 表示项目属性，1-10 表示分数
     * 1:1,2,3,4,5,6,7,8,9,10
     */
    @Column(name = "DATA")
    private String data;

    /**
     * 申请人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "APPLICANT_ID")
    @ToString.Exclude
    private Employee applicant;
    /**
     * 申请日期
     */
    @Column(name = "APPLY_DATE")
    private LocalDateTime applyTime;

    /**
     * 说明
     */
    @Column(name = "DESCRIPTION")
    private String description;

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

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