package com.lesingle.edu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lesingle.edu.entity.TaskFeedback;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Optional;

/**
 * 任务评价 Mapper
 */
@Mapper
public interface TaskFeedbackMapper extends BaseMapper<TaskFeedback> {

    /**
     * 根据完成记录ID查询评价
     */
    @Select("SELECT * FROM task_feedback WHERE completion_id = #{completionId} AND deleted = 0")
    Optional<TaskFeedback> findByCompletionId(@Param("completionId") Long completionId);

    /**
     * 根据任务ID和学生ID查询评价
     */
    @Select("SELECT tf.* FROM task_feedback tf " +
            "INNER JOIN task_completion tc ON tf.completion_id = tc.id " +
            "WHERE tf.task_id = #{taskId} AND tc.student_id = #{studentId} AND tf.deleted = 0")
    Optional<TaskFeedback> findByTaskIdAndStudentId(@Param("taskId") Long taskId, @Param("studentId") Long studentId);

}
