package cn.teammodel.repository;

import cn.teammodel.model.entity.common.Exam;
import cn.teammodel.model.vo.Common.ExamVo;
import com.azure.spring.data.cosmos.repository.CosmosRepository;
import com.azure.spring.data.cosmos.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

@Repository
public interface ExamRepository extends CosmosRepository<Exam, String> {

    @Query("select s.id,s.name,s.average,s.createTime from Exam as s join p in s.subjects where s.code = @code and array_contains(s.classes,@classId) and s.period.id = @periodId  and s.progress = 'finish' and p.id =@subjectId  order by s.createTime ")
    List<Exam> findExamByClassId(String code,String classId,String periodId,String subjectId);
    @Query("select * from Exam as s where s.code = @code and s.id = @id")
    List<Exam> findExamById(@Param("code")String code, @Param("id")String id);
    @Query("select s.id,s.name,s.average,s.classes,s.stuCount,s.createTime,s.lessonRecordId,s.papers from Exam as s where s.source = @source and s.lessonRecordId in (@ids)")
    List<ExamVo> findExamsByIds(String source, Collection<String> ids);
}
