package com.oguerreiro.resilient.repository;

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.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.oguerreiro.resilient.domain.InputDataUpload;
import com.oguerreiro.resilient.domain.Organization;

/**
 * Spring Data JPA repository for the InputDataUpload entity.
 */
@Repository
public interface InputDataUploadRepository
    extends ResilientJpaRepository<InputDataUpload, Long>, InputDataUploadRepositoryEntended {
  /* Interface ResilientJpaRepository eager fetching Override methods */
  /* **************************************************************** */
  @Override
  @Query(value = "select inputDataUpload from InputDataUpload inputDataUpload left join fetch inputDataUpload.period left join fetch inputDataUpload.owner", countQuery = "select count(inputDataUpload) from InputDataUpload inputDataUpload")
  Page<InputDataUpload> findAllWithEagerRelationships(Pageable pageable);

  @Query("select inputDataUpload from InputDataUpload inputDataUpload left join fetch inputDataUpload.period left join fetch inputDataUpload.owner")
  List<InputDataUpload> findAllWithEagerRelationships();

  @Query("select inputDataUpload from InputDataUpload inputDataUpload left join fetch inputDataUpload.period left join fetch inputDataUpload.owner where inputDataUpload.id =:id")
  Optional<InputDataUpload> findOneWithEagerRelationships(@Param("id") Long id);

  List<InputDataUpload> findByOwnerIn(List<Organization> oganizations);
}
