package studycave.studycaverestservice.model.test;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

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

public interface TestRepository extends JpaRepository<Test, Long> {

    Optional<Test> findByIdAndGroupId(Long testId, Integer groupId);

    @Query("select t from Test t where (t.permission = 'GROUP' and t.group.id = :g and t.status = 'VERIFIED' )")
    List<Test> findTestByGroup(@Param("g") Integer g);



    @Query("select t from Test t where (t.permission = 'GROUP' and t.group.id = :g and t.status = 'UNVERIFIED' )")
    List<Test> findWaitingTestByGroupKey(@Param("g") Integer g);


    List<Test> findAllByGroupIdOrderByAddDateDesc(Integer id);

}
