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

import it.sw.pa.comune.artegna.domain.UtenteApp;
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 UtenteApp entity.
 */
@Repository
public interface UtenteAppRepository extends JpaRepository<UtenteApp, Long> {
    Optional<UtenteApp> findByUsername(String username);

    default Optional<UtenteApp> findOneWithEagerRelationships(Long id) {
        return this.findOneWithToOneRelationships(id);
    }

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

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

    @Query(
        value = "select utenteApp from UtenteApp utenteApp left join fetch utenteApp.internalUser",
        countQuery = "select count(utenteApp) from UtenteApp utenteApp"
    )
    Page<UtenteApp> findAllWithToOneRelationships(Pageable pageable);

    @Query("select utenteApp from UtenteApp utenteApp left join fetch utenteApp.internalUser")
    List<UtenteApp> findAllWithToOneRelationships();

    @Query("select utenteApp from UtenteApp utenteApp left join fetch utenteApp.internalUser where utenteApp.id =:id")
    Optional<UtenteApp> findOneWithToOneRelationships(@Param("id") Long id);
}
