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.VariableClass;

/**
 * Spring Data JPA repository for the VariableClass entity.
 */
@Repository
public interface VariableClassRepository extends ResilientJpaRepository<VariableClass, Long> {
  /* Interface ResilientJpaRepository eager fetching Override methods */
  /* **************************************************************** */
  @Override
  @Query(value = "select variableClass from VariableClass variableClass", countQuery = "select count(variableClass) from VariableClass variableClass")
  Page<VariableClass> findAllWithEagerRelationships(Pageable pageable);

  @Override
  @Query("select variableClass from VariableClass variableClass")
  List<VariableClass> findAllWithEagerRelationships();

  @Override
  @Query("select variableClass from VariableClass variableClass where variableClass.id =:id")
  Optional<VariableClass> findOneWithEagerRelationships(@Param("id") Long id);

  @Query("select class from VariableClass class, Variable v where class.variableClassType=v.variableClassType and v.id = :variableId order by class.name")
  List<VariableClass> getAllForVariable(@Param("variableId") Long variableId);
}
