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

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

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

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

    @Query(
        value = "select conferma from Conferma conferma left join fetch conferma.confermataDa",
        countQuery = "select count(conferma) from Conferma conferma"
    )
    Page<Conferma> findAllWithToOneRelationships(Pageable pageable);

    @Query("select conferma from Conferma conferma left join fetch conferma.confermataDa")
    List<Conferma> findAllWithToOneRelationships();

    @Query("select conferma from Conferma conferma left join fetch conferma.confermataDa where conferma.id =:id")
    Optional<Conferma> findOneWithToOneRelationships(@Param("id") Long id);
}
