package cn.teammodel.repository;

import cn.teammodel.model.entity.school.School;
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.List;

/**
 * @author winter
 * @create 2023-11-28 17:39
 */
@Repository
public interface SchoolRepository extends CosmosRepository<School, String> {
    /**
    * 动态投影, 查询还是要将所有的值查出来,类的动态查询不能嵌套
    */
    @Query("select value p from School as s join p in s.period where s.id = @schoolId and s.code = 'Base' and p.id = @periodId")
    List<School.Period> findPeriodById(@Param("schoolId") String schoolId, @Param("periodId") String periodId);
    @Query("select value p.semesters from School as s join p in s.period where s.id = @schoolId and s.code = 'Base' and p.id = @periodId")
    List<School.Semester> findSemestersById(@Param("schoolId") String schoolId, @Param("periodId") String periodId);
    @Query("select value p.subjects from School as s join p in s.period where s.id = @schoolId and s.code = 'Base' and p.id = @periodId")
    List<School.Subject> findSubjectById(@Param("schoolId") String schoolId, @Param("periodId") String periodId);
    @Query("select s.period,s.subjects from School as s where s.id = @schoolId and s.code = 'Base' ")
    List<School> findBaseById(@Param("schoolId") String schoolId);
    @Query("select s.picture,s.areaId from School as s where s.id = @schoolId and s.code = 'Base' ")
    List<School> findBasePictureById(@Param("schoolId") String schoolId);
    School findSchoolByIdAndCode(String schoolId, String code);
}
