package io.gmss.fiscad.repositories.decoupage;

import io.gmss.fiscad.entities.decoupage.Arrondissement;
import io.gmss.fiscad.entities.decoupage.Quartier;
import io.gmss.fiscad.paylaods.response.QuartierSyncResponse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface QuartierRepository extends JpaRepository<Quartier, Long> {
    List<Quartier> getAllByArrondissement(Arrondissement arrondissement);

    @Query(value = "select q.id,q.code, q.nom, a.id as arrondissementid from arrondissement a " +
            " left join quartier q on q.arrondissement_id=a.id " +
            " left join arrondissements_structures sa on sa.arrondissement_id=a.id" +
            " where q.deleted is false and sa.structure_id = ?1 ", nativeQuery = true)
    List<QuartierSyncResponse> getQuartierResponse(Long structure_id);

    @Query(value = "select q.id,q.code, q.nom, a.id as arrondissementid from arrondissement a " +
            " left join quartier q on q.arrondissement_id=a.id " +
            " left join arrondissements_structures sa on sa.arrondissement_id=a.id" +
            " where q.deleted is false ", nativeQuery = true)
    List<QuartierSyncResponse> getAdminQuartierResponse();

}

