package it.sw.pa.comune.artegna.repository;

import it.sw.pa.comune.artegna.domain.Disponibilita;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * Spring Data JPA repository for the Disponibilita entity.
 */
@Repository
public interface DisponibilitaRepository extends JpaRepository<Disponibilita, Long> {
    default Optional<Disponibilita> findOneWithEagerRelationships(Long id) {
        return this.findOneWithToOneRelationships(id);
    }

    default List<Disponibilita> findAllWithEagerRelationships() {
        return this.findAllWithToOneRelationships();
    }

    default Page<Disponibilita> findAllWithEagerRelationships(Pageable pageable) {
        return this.findAllWithToOneRelationships(pageable);
    }

    @Query(
        value = "select disponibilita from Disponibilita disponibilita left join fetch disponibilita.struttura",
        countQuery = "select count(disponibilita) from Disponibilita disponibilita"
    )
    Page<Disponibilita> findAllWithToOneRelationships(Pageable pageable);

    @Query("select disponibilita from Disponibilita disponibilita left join fetch disponibilita.struttura")
    List<Disponibilita> findAllWithToOneRelationships();

    @Query("select disponibilita from Disponibilita disponibilita left join fetch disponibilita.struttura where disponibilita.id =:id")
    Optional<Disponibilita> findOneWithToOneRelationships(@Param("id") Long id);
}
