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

import io.gmss.fiscad.entities.infocad.metier.Enquete;
import io.gmss.fiscad.entities.infocad.parametre.Personne;
import io.gmss.fiscad.entities.rfu.metier.CaracteristiqueParcelle;
import io.gmss.fiscad.paylaods.response.restoration.CaracateristiqueParcellePayLoads;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

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


public interface CaracteristiqueParcelleRepository extends JpaRepository<CaracteristiqueParcelle, Long> {

    void deleteAllByEnquete(Enquete enquete);
    Optional<CaracteristiqueParcelle> findByMobileDataId(Long id);
    @Transactional
    @Modifying
    void deleteAllByEnquete_Id(Long enqueteId);

    List<CaracteristiqueParcelle> findAllByEnquete_Id(Long id);

    @Query(nativeQuery = true,
            value = "select cp.id as idBackend, " +
                    "cp.external_key as externalKey, " +
                    "c.external_key as caracteristiqueId, " +
                    "e.external_key as enqueteId, " +
                    "cp.valeur as valeur " +
                    "from caracteristique_parcelle cp " +
                    "inner join caracteristique c on cp.caracteristique_id = c.id " +
                    "inner join enquete e on cp.enquete_id = e.id " +
                    "where cp.terminal_id = ?")
    List<CaracateristiqueParcellePayLoads> getCaracteristiqueParcelleByTerminalId(Long terminalId);
}
