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

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_unite_logement " +
//                "SET deleted = true " +
//                "WHERE id = ?")
//@Where(clause = " deleted = false")
public class EnqueteUniteLogement extends BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private float surface;
    private int nbrePiece;
    private int nbreHabitant;
    private int nbreMenage;
    private boolean enLocation;
    private float montantMensuelLoyer;
    private int nbreMoisEnLocation;
    private float montantLocatifAnnuelDeclare;
    private float surfaceLouee;
    private boolean sbee;
    private boolean soneb;
    private String numCompteurSbee;
    private String numCompteurSoneb;
    @JsonFormat(pattern = "dd-MM-yyyy")
    @JsonDeserialize(using = LocalDateDeserializer.class)
    private LocalDate dateDebutExcemption;
    @JsonFormat(pattern = "dd-MM-yyyy")
    @JsonDeserialize(using = LocalDateDeserializer.class)
    private LocalDate dateFinExcemption;
    @JsonIgnore
    @ManyToOne
    private Enquete enquete;
    @ManyToOne
    private UniteLogement uniteLogement;
    private Long uniteLogementExternalKey;
    @OneToOne
    private Personne personne;
    private Long personneExternalKey;
    private Long mobileDataId;
    @OneToMany(mappedBy = "enqueteUniteLogement")
    @JsonManagedReference
    private List<CaracteristiqueUniteLogement> caracteristiqueUniteLogements;

    @JsonIgnore
    @ManyToOne
    private Tpe terminal;
    @JsonIgnore
    @ManyToOne
    private User user;
    //@JsonIgnore
    @OneToMany(mappedBy = "enqueteUniteLogement")
    private List<Upload> uploads;
    @JsonIgnore
    @Enumerated(EnumType.STRING)
    private StatutEnregistrement statutEnregistrement;
}
