package com.lesingle.edu.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lesingle.edu.dto.request.LessonCreateRequest;
import com.lesingle.edu.dto.request.LessonUpdateRequest;
import com.lesingle.edu.dto.request.LessonProgressRequest;
import com.lesingle.edu.dto.request.StudentRecordRequest;
import com.lesingle.edu.dto.response.StudentRecordsResponse;
import com.lesingle.edu.entity.Lesson;
import com.lesingle.edu.entity.LessonFeedback;
import com.lesingle.edu.entity.StudentRecord;

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

/**
 * 课时服务接口
 */
public interface LessonService extends com.baomidou.mybatisplus.extension.service.IService<Lesson> {

    Lesson createLesson(Long tenantId, LessonCreateRequest request);

    Lesson updateLesson(Long id, LessonUpdateRequest request);

    Lesson getLessonById(Long id);

    Page<Lesson> getLessonPage(Long tenantId, Integer pageNum, Integer pageSize, Long classId, Long teacherId, String status, LocalDate startDate, LocalDate endDate);

    Page<Lesson> getTeacherLessons(Long teacherId, Integer pageNum, Integer pageSize, String status, LocalDate startDate, LocalDate endDate);

    void deleteLesson(Long id);

    void startLesson(Long id);

    void completeLesson(Long id);

    void cancelLesson(Long id);

    /**
     * 教师退出上课：删除未完成的课时记录（非「已完成」），并回退课程包使用次数（与取消逻辑一致，已取消状态不再重复扣减）
     */
    void abandonLessonByTeacher(Long lessonId, Long teacherId, Long tenantId);

    List<Lesson> getTodayLessons(Long tenantId);

    /**
     * 获取学生记录列表（含课时信息、班级学生及记录，与前端结构对齐）
     */
    StudentRecordsResponse getStudentRecords(Long lessonId);

    /**
     * 保存学生记录
     */
    StudentRecord saveStudentRecord(Long lessonId, Long studentId, StudentRecordRequest request);

    /**
     * 批量保存学生记录
     */
    List<StudentRecord> batchSaveStudentRecords(Long lessonId, List<StudentRecordRequest> requests);

    /**
     * 获取课程反馈
     */
    LessonFeedback getLessonFeedback(Long lessonId);

    /**
     * 提交课程反馈
     */
    LessonFeedback submitFeedback(Long lessonId, Long teacherId, String content, Integer rating);

    /**
     * 保存课程进度
     */
    void saveLessonProgress(Long lessonId, LessonProgressRequest request);

    /**
     * 获取课程进度
     */
    Lesson getLessonProgress(Long lessonId);

    /**
     * 从排课创建课时
     *
     * @param schedulePlanId 排课 ID
     * @param teacherId      教师 ID
     * @return 创建的课时
     */
    Lesson createLessonFromSchedule(Long schedulePlanId, Long teacherId);

    /**
     * 从排课开始上课
     * 如果课时不存在则自动创建
     *
     * @param schedulePlanId 排课 ID
     * @param teacherId      教师 ID
     * @return 课时记录
     */
    Lesson startLessonFromSchedule(Long schedulePlanId, Long teacherId);

}
