package cn.com.qmth.stmms.biz.distributpaper.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import cn.com.qmth.stmms.biz.distributpaper.model.TryLibrary;
import cn.com.qmth.stmms.common.enums.LibraryStatus;

public interface TryLibraryDao extends PagingAndSortingRepository<TryLibrary, Integer>,
        JpaSpecificationExecutor<TryLibrary> {

    List<TryLibrary> findByExamIdAndBlockId(int examId, int blockId);

    List<TryLibrary> findByExamIdAndBlockIdAndStatusAndIsChecked(int examId, int blockId, LibraryStatus status,
            boolean isChecked);

    List<TryLibrary> findByBlockIdAndSecretNo(int blockId, int secretNo);

    List<TryLibrary> findByExamIdAndBlockIdAndGetterAndStatus(int examId, int blockId, int getter, LibraryStatus status);

    List<TryLibrary> findByExamIdAndBlockIdAndStatus(int examId, int blockId, LibraryStatus status);

    List<TryLibrary> findByExamIdAndSubjectCodeAndBlockIdAndSecretNoAndStatus(int examId, String subjectCode, int blockId, int secretNo, LibraryStatus status);

    @Modifying
    @Query("update TryLibrary f set f.status=?2 where f.id=?1")
    void updateStatusById(int id, LibraryStatus status);

}
