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

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

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


public interface BatimentRepository extends JpaRepository<Batiment, Long> {
    Optional<Batiment> findByMobileDataId(Long id);
    Optional<Batiment> findFirstByExternalKeyAndTerminal_Id(Long externalKey, Long TerminalId);

    @Query(value = "SELECT " +
            " b.id as idBackend," +
            " b.external_key as externalKey," +
            " b.nub as nub, " +
            " b.code as code," +
            " b.date_construction as dateConstruction," +
            " p.external_key as parcelleId," +
            " b.terminal_id as terminalId " +
            " FROM batiment b inner join parcelle p on b.id = b.parcelle_id " +
            " WHERE b.terminal_id = ?1", nativeQuery = true)
    List<BatimentPayload> getBatimentByTerminalId(Long terminalId);

    void deleteByEnqueteId(Long enqueteId);
}
