package io.gmss.fiscad.entities.infocad.parametre;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.entities.infocad.metier.Piece;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

@EqualsAndHashCode(callSuper = true)
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@SQLDelete(sql =
        "UPDATE source_droit " +
                "SET deleted = true " +
                "WHERE id = ?")
@Where(clause = " deleted = false")
public class SourceDroit extends BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String libelle;
    @Column(columnDefinition = "integer default 1")
    private int tailleChampMin;
    @Column(columnDefinition = "integer default 5")
    private int tailleChampMax;
    @Column(columnDefinition = "varchar(255) default 'text'")
    private String typeChamp;
    @Column(columnDefinition = "boolean default false")
    private boolean temoin;
    @ManyToMany
    @JoinTable(name = "sourcesDeDroits_ModesAcquisitions",
            joinColumns = @JoinColumn(name = "sources_droits_id"),
            inverseJoinColumns = @JoinColumn(name = "modes_acquisitions_id")
    )
    private Set<ModeAcquisition> modeAcquisitions;
    @JsonIgnore
    @OneToMany(mappedBy = "sourceDroit")
    //private List<SourceDroitExerce> sourceDroitExerces;
    private List<Piece> pieces;
    @Column(columnDefinition = "boolean default false")
    private boolean titreFoncier;

}
