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

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

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


public interface UniteLogementRepository extends JpaRepository<UniteLogement, Long> {
    Optional<UniteLogement> findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long TerminalId);
    Optional<UniteLogement> findByMobileDataId(Long id);
    @Query(
            nativeQuery = true,
            value = "select ul.id as idBackend, " +
                    " ul.external_key as externalKey, " +
                    " ul.terminal_id as terminalId, " +
                    " ul.nul as nul, " +
                    " ul.numero_etage as numeroEtage, " +
                    " ul.code as code, " +
                    " ul.batiment_id as batimentId " +
                    "    from unite_logement ul " +
                    "    inner join batiment b on b.id = ul.batiment_id " +
                    "    where ul.terminal_id = ?1"
    )
    List<UniteLogementPayLoad> getUniteLogementByTerminalId(Long terminalId);

  void deleteByEnqueteId(Long enqueteId);
}
