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

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

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

public interface PersonneRepository extends JpaRepository<Personne, Long> {
    Optional<Personne> findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long TerminalId);

    Optional<Personne> findByMobileDataId(Long id);
    @Query(value = "Select  " +
            " p.id as idBackend, " +
            " p.ifu, " +
            " p.external_key as externalKey, " +
            " p.nom_ou_sigle as nomOuSigle, " +
            " p.prenom_ou_raison_sociale as prenomOuRaisonSociale, " +
            " p.num_ravip as numRavip, " +
            " p.npi, " +
            " p.date_naissance_ou_consti as dateNaissanceOuConsti, " +
            " p.lieu_naissance as lieuNaissance, " +
            " p.tel1," +
            " p.tel2," +
            " p.adresse," +
            " p.categorie, " +
            " p.situation_matrimoniale_id as situationMatrimonialeId, " +
            " p.nationalite_id as nationaliteId, " +
            " p.type_personne_id as typePersonneId, " +
            " p.profession_id as professionId," +
            " p.commune_id as communeId," +
            " p.observation as Observation," +
            " p.synchronise," +
            " p.terminal_id as terminalId, " +

            " p.have_representant as haveRepresentant, " +
            " p.ravip_question as ravipQuestion, " +
            " p.age as age, " +
            " p.nom_jeune_fille as nomJeuneFille, " +
            " p.nom_mere as nomMere, " +
            " p.prenom_mere as prenomMere, " +
            " p.indicatif_tel1 as indicatifTel1, " +
            " p.indicatif_tel2 as indicatifTel2, " +
            " p.sexe as sexe, " +
            " p.must_have_representant as mustHaveRepresentant, " +
            " p.file_path as filePath " +
            " From personne p  " +
            " where p.terminal_id = ?1", nativeQuery = true)
    List<PersonnePayLoad> getPersonnesByTerminalId(Long terminalId);


}
