package io.gmss.fiscad.entities.rfu.metier;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.gmss.fiscad.deserializer.LocalDateDeserializer;
import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.entities.infocad.metier.Enquete;
import io.gmss.fiscad.entities.infocad.metier.Tpe;
import io.gmss.fiscad.entities.infocad.metier.Upload;
import io.gmss.fiscad.entities.infocad.parametre.Personne;
import io.gmss.fiscad.entities.user.User;
import io.gmss.fiscad.enums.StatutEnregistrement;
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.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

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

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private float surfaceAuSol;
    private String autreMenuisierie;
    private String autreMur;
    private boolean sbee;
    private String numCompteurSbee;
    private boolean soneb;
    private String numCompteurSoneb;
    private int nbreLotUnite;
    private int nbreUniteLocation;
    private float surfaceLouee;
    private int nbreMenage;
    private int nbreHabitant;
    private float valeurMensuelleLocation;
    private int nbreMoisLocation;
    private String autreCaracteristiquePhysique;
    @JsonFormat(pattern = "dd-MM-yyyy")
    @JsonDeserialize(using = LocalDateDeserializer.class)
    private LocalDate dateDebutExcemption;
    @JsonFormat(pattern = "dd-MM-yyyy")
    @JsonDeserialize(using = LocalDateDeserializer.class)
    private LocalDate dateFinExcemption;
    @OneToOne
    private Personne personne;
    private Long personneExternalKey;
    @ManyToOne
    private Batiment batiment;
    private Long batimentExternalKey;

    @JsonIgnore
    @ManyToOne
    private Enquete enquete;


    @JsonManagedReference   ///pour couper la récurcivité
    @OneToMany(mappedBy = "enqueteBatiment")
    private List<CaracteristiqueBatiment> caracteristiqueBatiments;

    @JsonIgnore
    @ManyToOne
    private Tpe terminal;
    @JsonIgnore
    @ManyToOne
    private User user;
    private Long mobileDataId;
    //@JsonIgnore
    @OneToMany(mappedBy = "enqueteBatiment")
    private List<Upload> uploads;

    @Enumerated(EnumType.STRING)
    @JsonIgnore
    private StatutEnregistrement statutEnregistrement;
}
