package com.ecep.contract.model;

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

import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import com.ecep.contract.BlackReasonType;
import com.ecep.contract.util.HibernateProxyUtils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

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.Index;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "COMPANY_BLACK_REASON", schema = "supplier_ms", indexes = {
        @Index(name = "COMPANY_ID", columnList = "COMPANY_ID")
})
// @org.springframework.data.relational.core.mapping.Table("COMPANY_BLACK_REASON")
@JsonIgnoreProperties(ignoreUnknown = true)
public class CompanyBlackReason implements IdentityEntity, CompanyBasedEntity, Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Integer id;

    @ManyToOne(fetch = FetchType.LAZY)
    @OnDelete(action = OnDeleteAction.CASCADE)
    @JoinColumn(name = "COMPANY_ID")
    private Company company;

    @Column(name = "TYPE")
    private BlackReasonType type;

    @Column(name = "APPLY_NAME")
    private String applyName;

    @Column(name = "APPLY_DATE")
    private LocalDate applyDate;

    @Column(name = "UPDATE_TIME")
    private LocalDate updateTime;

    @Column(name = "CREATE_TIME")
    private LocalDate createTime;

    @Column(name = "INCLUDE_DATE")
    private LocalDate includeDate;

    @Column(name = "BLACK_REASON")
    private String blackReason;

    @Lob
    @Column(name = "DESCRIPTION", columnDefinition = "TEXT")
    private String description;

    @Column(name = "`KEY`")
    private String key;

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

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