package vn.azteam.tpf.repository;

import vn.azteam.tpf.domain.TBSupplies;
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 TBSupplies entity.
 */
@SuppressWarnings("unused")
@Repository
public interface TBSuppliesRepository extends JpaRepository<TBSupplies, Long>, JpaSpecificationExecutor<TBSupplies> {

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

    @Query(value = "select distinct tb_supplies from TBSupplies tb_supplies left join fetch tb_supplies.tbGuidelines")
    List<TBSupplies> findAllWithEagerRelationships();

    @Query("select tb_supplies from TBSupplies tb_supplies left join fetch tb_supplies.tbGuidelines where tb_supplies.id =:id")
    Optional<TBSupplies> findOneWithEagerRelationships(@Param("id") Long id);

    Optional<TBSupplies> findFirstBySkuOrName(String sku, String name);
}
