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

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.entities.decoupage.Arrondissement;
import io.gmss.fiscad.entities.decoupage.Commune;
import io.gmss.fiscad.entities.user.User;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
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;


/**
 * représente un centre d'impôt dans le cadre d'une enquête fiscale
 */
@EqualsAndHashCode(callSuper = true)
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@SQLDelete(sql =
        "UPDATE structure " +
                "SET deleted = true " +
                "WHERE id = ?")
@Where(clause = " deleted = false")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Structure extends BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(updatable = false)
    private String code;
    private String nom;
    private String ifu;
    private String rccm;
    private String tel;
    private String email;
    private String adresse;
    @NotNull
    @ManyToOne
    private Commune commune;
    //@JsonIgnore
    @ManyToMany
    @JoinTable(name = "arrondissements_structures",
            joinColumns = @JoinColumn(name = "structure_id"),
            inverseJoinColumns = @JoinColumn(name = "arrondissement_id")
    )
    private Set<Arrondissement> arrondissements;
//    @JsonIgnore
//    @OneToMany(mappedBy = "structure")
//    private List<User> agents;
//    @JsonIgnore
//    @OneToMany(mappedBy = "structure")
//    private List<Bloc> blocs;

}
