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

import it.sw.pa.comune.artegna.domain.Liberatoria;
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 Liberatoria entity.
 */
@Repository
public interface LiberatoriaRepository extends JpaRepository<Liberatoria, Long> {
    default Optional<Liberatoria> findOneWithEagerRelationships(Long id) {
        return this.findOneWithToOneRelationships(id);
    }

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

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

    @Query(
        value = "select liberatoria from Liberatoria liberatoria left join fetch liberatoria.utente",
        countQuery = "select count(liberatoria) from Liberatoria liberatoria"
    )
    Page<Liberatoria> findAllWithToOneRelationships(Pageable pageable);

    @Query("select liberatoria from Liberatoria liberatoria left join fetch liberatoria.utente")
    List<Liberatoria> findAllWithToOneRelationships();

    @Query("select liberatoria from Liberatoria liberatoria left join fetch liberatoria.utente where liberatoria.id =:id")
    Optional<Liberatoria> findOneWithToOneRelationships(@Param("id") Long id);
}
