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


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.entities.decoupage.Quartier;
import io.gmss.fiscad.enums.StatutParcelle;
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 org.locationtech.jts.geom.Polygon;
import org.n52.jackson.datatype.jts.GeometryDeserializer;
import org.n52.jackson.datatype.jts.GeometrySerializer;

import java.io.Serializable;

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

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String q;
    private String ilot;
    private String zone;
    private String p;
    @Column(unique = true,nullable = true)
    private String nup;
    @Column(unique = true,nullable = true)
    private String nupProvisoire;
    private String longitude;
    private String latitude;
    private String pointsPolygone;
    //////////
    private String departement;
    private String commune;
    private String arrondissement;
    private String villageQuartier;
    private String codeBloc;
    //private String codeParcelle;
    private String codeEquipe;
    private Integer superficie;
    private String elNumeroEtatLieux;
    private String elLot;
    private String elLettreParcelle;
    private String rfuQuartierOuZone;
    private String rfuIlot;
    private String rfuLettreParcelle;
    private String dateCollecte;
    private String nomLotissement;
    private String nomEtPrenoms;
    private String sourceCollecte;
    private String observations;


    @Enumerated(EnumType.STRING)
    private StatutParcelle statutParcelle;

//    @JsonIgnore
//    @ManyToOne
//    private Upload upload;

    private Long uploadId;


    ////////////

//    @JsonIgnore
//    @OneToOne
//    private Parcelle parcelle;

    @ManyToOne
    private Quartier quartier;

    @ColumnDefault("0")
    private int  geomSrid;

//    @JsonSerialize(using = GeometrySerializer.class)
//    @JsonDeserialize(contentUsing = GeometryDeserializer.class)
//    @Column(name = "geom",columnDefinition = "geometry(Polygon,4326)")
//    private Polygon geometry ;

    @JsonSerialize(using = GeometrySerializer.class)
    @JsonDeserialize(contentUsing = GeometryDeserializer.class)
    @Column(name = "geometry",columnDefinition = "geometry(Polygon,32631)")
    private Polygon geometry;

    @Column(columnDefinition = "TEXT")
    private String geometryString;
}
