package com.magistr.app.repository;

import com.magistr.app.model.ScheduleOverride;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

public interface ScheduleOverrideRepository extends JpaRepository<ScheduleOverride, Long> {

    @Query("""
            select o
            from ScheduleOverride o
            left join fetch o.baseRuleSlot baseSlot
            left join fetch o.newTimeSlot
            left join fetch o.newClassroom
            left join fetch o.newTeacher
            where o.lessonDate between :startDate and :endDate
            """)
    List<ScheduleOverride> findByLessonDateBetweenWithDetails(
            @Param("startDate") LocalDate startDate,
            @Param("endDate") LocalDate endDate
    );

    Optional<ScheduleOverride> findByBaseRuleSlotIdAndLessonDate(Long baseRuleSlotId, LocalDate lessonDate);
}
