package com.fs.course.mapper;

import java.util.List;
import java.util.Map;

import com.fs.course.domain.FsUserVideoLike;
import com.fs.course.dto.VideoLikeStatusDTO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 课堂视频点赞Mapper接口
 *
 * @author fs
 * @date 2024-05-15
 */
public interface FsUserVideoLikeMapper
{
    /**
     * 查询课堂视频点赞
     *
     * @param likeId 课堂视频点赞主键
     * @return 课堂视频点赞
     */
    public FsUserVideoLike selectFsUserVideoLikeByLikeId(Long likeId);

    /**
     * 查询课堂视频点赞列表
     *
     * @param fsUserVideoLike 课堂视频点赞
     * @return 课堂视频点赞集合
     */
    public List<FsUserVideoLike> selectFsUserVideoLikeList(FsUserVideoLike fsUserVideoLike);

    /**
     * 新增课堂视频点赞
     *
     * @param fsUserVideoLike 课堂视频点赞
     * @return 结果
     */
    public int insertFsUserVideoLike(FsUserVideoLike fsUserVideoLike);

    /**
     * 修改课堂视频点赞
     *
     * @param fsUserVideoLike 课堂视频点赞
     * @return 结果
     */
    public int updateFsUserVideoLike(FsUserVideoLike fsUserVideoLike);

    /**
     * 删除课堂视频点赞
     *
     * @param likeId 课堂视频点赞主键
     * @return 结果
     */
    public int deleteFsUserVideoLikeByLikeId(Long likeId);

    /**
     * 批量删除课堂视频点赞
     *
     * @param likeIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsUserVideoLikeByLikeIds(Long[] likeIds);


    @Select("select ifnull(count(1),0) from fs_user_video_like  where video_id =#{videoId} and user_id=#{userId}")
    int checkLike(@Param("videoId") Long videoId, @Param("userId")long userId);


    @Delete("delete from fs_user_video_like  where  video_id=#{videoId} and user_id=#{userId} ")
    int deleteLike(@Param("videoId") Long videoId,@Param("userId")long userId);


    @Select("<script>" +
            "select video_id, ifnull(count(1), 0) > 0 as liked " +
            "from fs_user_video_like " +
            "where video_id in " +
            "<foreach item='videoId' collection='videoIds' open='(' separator=',' close=')'>" +
            "#{videoId}" +
            "</foreach> " +
            "and user_id = #{userId} " +
            "group by video_id" +
            "</script>")
    @MapKey("videoId")
    Map<Long, VideoLikeStatusDTO> checkLikes(@Param("videoIds") List<Long> videoIds, @Param("userId") long userId);
}
