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

import io.gmss.fiscad.entities.infocad.metier.Parcelle;
import io.gmss.fiscad.entities.infocad.parametre.Personne;
import io.gmss.fiscad.paylaods.response.restoration.ParcellePayLoad;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface ParcelleRepository extends JpaRepository<Parcelle, Long> {
    Optional<Parcelle> findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long TerminalId);
    Optional<Parcelle> findByMobileDataId(Long id);
    @Query(value = "Select  " +
            " p.id as idBackend, " +
            " p.external_key as externalKey, " +
            " p.q, " +
            " p.nup," +
            " p.nup_provisoire as nupProvisoire, " +
            " p.longitude, " +
            " p.latitude, " +
            " p.situation_geographique as situationGeographique, " +
            " p.nature_domaine_id as natureDomaineId, " +
            " p.quartier_id as quartierId, " +
            " p.i, " +
            " p.p, " +
            " p.num_titre_foncier as numTitreFoncier, " +
            " p.observation as observation, " +
            " p.synchronise, " +
            " p.terminal_id as terminalId, " +

            " p.type_domaine_id as typeDomaineId, " +
            " p.numero_provisoire as numeroProvisoire, " +
            " p.bloc_id as blocId " +
            //    " p.geom_srid as geomSrid " +
            " From parcelle p  " +
            " where p.terminal_id = ?1", nativeQuery = true)
    List<ParcellePayLoad> getParcellesByTerminalId(Long terminalId);

   List<Parcelle> findAllByQuartier_Arrondissement_Commune_Id(Long communeId);
    Optional<Parcelle> findFirstByNupProvisoire(String nump);
}
