package com.ruoyi.course.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.ruoyi.course.domain.ScheduleItem;

import java.util.List;

/**
 * <p>
 * 排课项表（具体的一节课安排） Mapper 接口
 * </p>
 *
 * @author xu
 * @since 2025-12-17
 */
@Mapper
public interface ScheduleItemMapper extends BaseMapper<ScheduleItem> {


    @Select("SELECT * FROM schedule_item WHERE grade = #{grade} AND semester = #{semester}")
    List<ScheduleItem> selectByGradeAndSemester(@Param("grade") String grade,
                                                @Param("semester") String semester);

    @Select("SELECT si.* FROM schedule_item si " +
            "INNER JOIN student_schedule ss ON si.id = ss.schedule_item_id " +
            "WHERE ss.student_id = #{studentId}")
    List<ScheduleItem> selectByStudentId(@Param("studentId") Long studentId);

    @Select("SELECT * FROM schedule_item WHERE class_id = #{classId}")
    List<ScheduleItem> selectByClassId(@Param("classId") Long classId);

    @Delete("DELETE FROM schedule_item WHERE semester = #{semester}")
    int deleteBySemester(@Param("semester") String semester);

    @Select("SELECT si.* FROM schedule_item si " +
            "WHERE si.teacher_id = #{teacherId} AND si.time_slot_id = #{timeSlotId}")
    List<ScheduleItem> findTeacherTimeConflicts(@Param("teacherId") Long teacherId,
                                                @Param("timeSlotId") Long timeSlotId);

}
