package vn.azteam.tpf.repository;

import vn.azteam.tpf.domain.TBCrop;
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;

import java.util.List;
import java.util.Optional;

/**
 * Spring Data  repository for the TBCrop entity.
 */
@SuppressWarnings("unused")
@Repository
public interface TBCropRepository extends JpaRepository<TBCrop, Long>, JpaSpecificationExecutor<TBCrop> {

    @Query(value = "select distinct tb_crop from TBCrop tb_crop left join fetch tb_crop.tbDetailUsers",
        countQuery = "select count(distinct tb_crop) from TBCrop tb_crop")
    Page<TBCrop> findAllWithEagerRelationships(Pageable pageable);

    @Query(value = "select distinct tb_crop from TBCrop tb_crop left join fetch tb_crop.tbDetailUsers")
    List<TBCrop> findAllWithEagerRelationships();

    @Query("select tb_crop from TBCrop tb_crop left join fetch tb_crop.tbDetailUsers where tb_crop.id =:id")
    Optional<TBCrop> findOneWithEagerRelationships(@Param("id") Long id);

}
