package com.fs.course.mapper;

import com.fs.course.domain.FsCourseAnswerLogs;
import com.fs.course.param.FsCourseAnswerLogsParam;
import com.fs.course.vo.FsCourseAnswerLogsListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 答题日志Mapper接口
 *
 * @author fs
 * @date 2024-09-11
 */
public interface FsCourseAnswerLogsMapper
{
    /**
     * 查询答题日志
     *
     * @param logId 答题日志主键
     * @return 答题日志
     */
    public FsCourseAnswerLogs selectFsCourseAnswerLogsByLogId(Long logId);

    /**
     * 查询答题日志列表
     *
     * @param fsCourseAnswerLogs 答题日志
     * @return 答题日志集合
     */
    public List<FsCourseAnswerLogs> selectFsCourseAnswerLogsList(FsCourseAnswerLogs fsCourseAnswerLogs);


    public List<FsCourseAnswerLogsListVO> selectFsCourseAnswerLogsListVO(@Param("map") FsCourseAnswerLogsParam param);
    public Long selectFsCourseAnswerLogsListVOCount(@Param("map") FsCourseAnswerLogsParam param);

    /**
     * 新增答题日志
     *
     * @param fsCourseAnswerLogs 答题日志
     * @return 结果
     */
    public int insertFsCourseAnswerLogs(FsCourseAnswerLogs fsCourseAnswerLogs);

    /**
     * 修改答题日志
     *
     * @param fsCourseAnswerLogs 答题日志
     * @return 结果
     */
    public int updateFsCourseAnswerLogs(FsCourseAnswerLogs fsCourseAnswerLogs);

    /**
     * 删除答题日志
     *
     * @param logId 答题日志主键
     * @return 结果
     */
    public int deleteFsCourseAnswerLogsByLogId(Long logId);

    /**
     * 批量删除答题日志
     *
     * @param logIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsCourseAnswerLogsByLogIds(Long[] logIds);

    @Select({"<script> " +
            "select * from fs_course_answer_logs where video_id = #{videoId} and user_id = #{userId} and is_right = 1 " +
            "<if test = 'qwUserId !=null '> " +
            "and qw_user_id = #{qwUserId} " +
            "</if>" +
            "limit 1 " +
            "</script>"})
    FsCourseAnswerLogs selectRightLogByCourseVideo(@Param("videoId") Long videoId,@Param("userId") Long userId,@Param("qwUserId") String qwUserId);


    @Select({"<script> " +
            "select * from fs_course_answer_logs where watch_log_id = #{watchLogId} and is_right = 1 " +
            "limit 1 " +
            "</script>"})
    FsCourseAnswerLogs selectRightLogByCourseVideoByFsUser(Long watchLogId);


    @Select({"<script> " +
            "select count(0) from fs_course_answer_logs where video_id = #{videoId} and user_id = #{userId} and is_right = 0 " +
            "<if test = 'qwUserId !=null '> " +
            "and qw_user_id = #{qwUserId} " +
            "</if>" +
            "</script>"})
    int selectErrorCountByCourseVideo(@Param("videoId") Long videoId,@Param("userId") Long userId,@Param("qwUserId") String qwUserId);

    List<FsCourseAnswerLogsListVO> selectFsCourseAnswerLogsListVONew(FsCourseAnswerLogsParam param);
    Long selectFsCourseAnswerLogsListVONewCount(FsCourseAnswerLogsParam param);

    /**
     * 查询领取次数
     *
     * @param userId   用户ID
     * @param videoId  小节ID
     * @return count
     */
    @Select("select count(log_id) from fs_course_red_packet_log where user_id = #{userId} and video_id = #{videoId}")
    Long selectRedStatus(@Param("userId") Long userId, @Param("videoId") Long videoId);
}
