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.Modifying;
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.InputDataUploadLog;

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

  @Override
  @Query("select inputDataUploadLog from InputDataUploadLog inputDataUploadLog left join fetch inputDataUploadLog.inputDataUpload")
  List<InputDataUploadLog> findAllWithEagerRelationships();

  @Override
  @Query("select inputDataUploadLog from InputDataUploadLog inputDataUploadLog left join fetch inputDataUploadLog.inputDataUpload where inputDataUploadLog.id =:id")
  Optional<InputDataUploadLog> findOneWithEagerRelationships(@Param("id") Long id);

  /* Custom InputDataUploadLogRepository methods */
  /* ******************************************* */
  Integer countByInputDataUpload(InputDataUpload inputDataUpload);

  @Query("select inputDataUploadLog from InputDataUploadLog inputDataUploadLog left join fetch inputDataUploadLog.inputDataUpload inputDataUpload where inputDataUpload.id =:id")
  List<InputDataUploadLog> findAllByInputDataUploadId(@Param("id") Long id);

  @Modifying
  @Query("delete from InputDataUploadLog l where l.inputDataUpload=:inputDataUpload")
  void deleteAllByInputDataUpload(@Param("inputDataUpload") InputDataUpload inputDataUpload);
}
