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

import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.entities.infocad.metier.ActeurConcerne;
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.Set;

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

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String libelle;
    @ManyToOne
    private SourceDroit sourceDroit;
    @ManyToOne
    private ActeurConcerne acteurConcerne;
    @ManyToMany
    @JoinTable(name = "pieces_sources_droits_exerces",
            joinColumns = @JoinColumn(name = "sources_droits_exerce_id"),
            inverseJoinColumns = @JoinColumn(name = "piece_id")
    )
    private Set<Piece> pieces;
    @ManyToOne
    private ModeAcquisition modeAcquisition;
}
