package cn.teammodel.repository;

import cn.teammodel.model.entity.school.LessonRecord;
import cn.teammodel.model.vo.appraise.RecordVo;
import com.azure.spring.data.cosmos.repository.CosmosRepository;
import com.azure.spring.data.cosmos.repository.Query;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface LessonRecordRepository extends CosmosRepository<LessonRecord, String> {
    @Query("select c.id,c.tmdid,c.name,c.groupIds,c.startTime,c.clientInteractionCount,c.clientInteractionAverge from LessonRecord as c where " +
            "c.code = @code and " +
            "(IS_NULL(@startTime) OR c.startTime >= @startTime) and " +
            "(IS_NULL(@endTime) OR c.startTime <= @endTime)  and "+
            "(IS_NULL(@grade) OR ARRAY_CONTAINS(c.grade, @grade)) and " +
            "c.status != 404 and "+
            "(IS_NULL(@periodId) OR c.periodId = @periodId)  and "+
            "(IS_NULL(@subjectId) OR c.subjectId = @subjectId)  and "+
            "(IS_NULL(@tmdId) OR c.tmdid = @tmdId)")
    Slice<LessonRecord> getLessonsByConditions(String code, Long startTime, Long endTime,String subjectId,String tmdId,String grade,String periodId,Pageable pageable);


    @Query("select c.startTime from LessonRecord as c where c.code = @code and c.expire<=0  and c.status<>404 and c.tmdid = @tmdId and c.periodId = @periodId and" +
            "(IS_NULL(@subjectId) or c.subjectId = @subjectId) ")
    Slice<LessonRecord> findAllByAcademicYearId(String code, String tmdId,String subjectId,String periodId,Pageable pageable);
    @Query("select c.startTime from LessonRecord as c where c.code = @code and c.expire<=0  and c.status<>404 and array_contains(c.grade,@grade) and c.periodId = @periodId and" +
            "(IS_NULL(@subjectId) or c.subjectId = @subjectId) ")
    Slice<LessonRecord> findAllByGrade(String code, String grade,String subjectId,String periodId,Pageable pageable);
    @Query("select c.startTime from LessonRecord as c where c.code = @code and c.expire<=0  and c.status<>404 and c.periodId = @periodId and" +
            "(IS_NULL(@subjectId) or c.subjectId = @subjectId) ")
    Slice<LessonRecord> findAll(String code,String subjectId,String periodId,Pageable pageable);

}
