package cn.com.qmth.examcloud.core.questions.dao;

import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
import cn.com.qmth.examcloud.core.questions.dao.entity.Paper;
import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetail;
import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetailUnit;
import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.repository.query.QueryByExampleExecutor;

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


public interface PaperDetailUnitRepo extends MongoRepository<PaperDetailUnit, String>, QueryByExampleExecutor<PaperDetailUnit> {
    List<PaperDetailUnit> findByPaperDetailOrderByNumber(PaperDetail paperDetail);

    List<PaperDetailUnit> findByPaperOrderByNumber(Paper paper);

    List<PaperDetailUnit> findByPaper(Paper paper);

    List<PaperDetailUnit> findByPaperId(String paperId);

    List<PaperDetailUnit> findByPaperIdOrderByNumber(String paperId);

    List<PaperDetailUnit> findByQuestion(Question question);

    List<PaperDetailUnit> findByQuestionIn(List<Question> questionList);

    Optional<PaperDetailUnit> findById(String id);

    List<PaperDetailUnit> findByQuestionType(QuesStructType quesType);

    Long countByPaperDetail(PaperDetail paperDetail);

    /**
     * 查询大题下的小题
     * 按number降序排列，取第一个，也就是number最大那个
     *
     * @param paperDetail
     * @return
     */
    PaperDetailUnit findTopByPaperDetailOrderByNumberDesc(PaperDetail paperDetail);

    /**
     * 查询大题下的小题
     * 按number升序排列，取第一个，也就是number最小那个
     *
     * @param paperDetail
     * @return
     */
    PaperDetailUnit findTopByPaperDetailOrderByNumberAsc(PaperDetail paperDetail);

    /**
     * 查询试卷中的第几个试题
     *
     * @param paper
     * @param number
     * @return
     */
    PaperDetailUnit findByPaperAndNumber(Paper paper, Integer number);

	void deleteByOrgId(Long toRootOrgId);
}
