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

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
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.parametre.ModeAcquisition;
import io.gmss.fiscad.entities.infocad.parametre.Personne;
import io.gmss.fiscad.entities.infocad.parametre.SourceDroit;
import io.gmss.fiscad.entities.infocad.parametre.TypePiece;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;

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

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String url;
    private String numeroPiece;
    @JsonFormat(pattern = "dd-MM-yyyy")
    @JsonDeserialize(using = LocalDateDeserializer.class)
    private LocalDate dateExpiration;
    @ManyToOne
    private TypePiece typePiece;
    private Long mobileDataId;
    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    private Personne personne;
    private Long personneExternalKey;
    @JsonIgnore
    @JsonBackReference
    @ManyToOne(fetch = FetchType.LAZY)
    private ActeurConcerne acteurConcerne;
    private Long acteurConcerneExternalKey;

    @ManyToOne
    private SourceDroit sourceDroit;

    @ManyToOne
    private ModeAcquisition modeAcquisition;

    @OneToMany(mappedBy = "piece")
    private List<Upload> uploads;

    @JsonIgnore
    @ManyToOne
    private Tpe terminal;


    private Long max_numero_piece_id;
    private Long max_numero_acteur_concerne_id;
    private Long enqueteId;
    private Long blocId;
    @ColumnDefault("false")
    private boolean synchronise;
    private String observation;

}
