package com.fs.course.mapper;

import java.util.List;
import com.fs.course.domain.FsUserVideoComment;
import com.fs.course.vo.FsUserVideoCommentListUVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 课堂视频评论Mapper接口
 *
 * @author fs
 * @date 2024-05-15
 */
public interface FsUserVideoCommentMapper
{
    /**
     * 查询课堂视频评论
     *
     * @param commentId 课堂视频评论主键
     * @return 课堂视频评论
     */
    public FsUserVideoComment selectFsUserVideoCommentByCommentId(Long commentId);

    /**
     * 查询课堂视频评论列表
     *
     * @param fsUserVideoComment 课堂视频评论
     * @return 课堂视频评论集合
     */
    public List<FsUserVideoComment> selectFsUserVideoCommentList(FsUserVideoComment fsUserVideoComment);

    /**
     * 新增课堂视频评论
     *
     * @param fsUserVideoComment 课堂视频评论
     * @return 结果
     */
    public int insertFsUserVideoComment(FsUserVideoComment fsUserVideoComment);

    /**
     * 修改课堂视频评论
     *
     * @param fsUserVideoComment 课堂视频评论
     * @return 结果
     */
    public int updateFsUserVideoComment(FsUserVideoComment fsUserVideoComment);

    /**
     * 删除课堂视频评论
     *
     * @param commentId 课堂视频评论主键
     * @return 结果
     */
    public int deleteFsUserVideoCommentByCommentId(Long commentId);

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

    @Select("SELECT c.*,u.nick_name,u.avatar FROM fs_user_video_comment c " +
            "left join fs_user u on u.user_id = c.user_id " +
            " WHERE c.video_id = #{videoId} and c.parent_id is null ORDER BY c.create_time DESC")
    List<FsUserVideoCommentListUVO> selectFsUserVideoCommentListByVideoId(@Param("videoId") Long videoId);

    @Select("SELECT c.*,u.nick_name,u.avatar FROM fs_user_video_comment c " +
            "left join fs_user u on u.user_id = c.user_id " +
            " WHERE c.parent_id = #{parentId} ORDER BY c.create_time DESC")
    List<FsUserVideoCommentListUVO> selectFsUserVideoCommentListByParentId(@Param("parentId") String parentId);


    void batchInsertComments(@Param("comments") List<FsUserVideoComment> comments);

    @Update("UPDATE fs_user_video_comment SET reply_count = #{replyCount} WHERE comment_id = #{commentId}")
    void updateReplyCount(@Param("commentId") Long commentId, @Param("replyCount") Integer replyCount);

    @Update("update fs_user_video_comment set likes=likes+1 where comment_code=#{commentCode}")
    int addLikes(String commentCode);


    @Update("update fs_user_video_comment set likes=likes-1 where comment_code=#{commentCode}")
    int minusLikes(String commentCode);

    @Delete("DELETE FROM fs_user_video_comment WHERE video_id = #{videoId}")
    void deleteByVideoId(String videoId);


    @Delete("DELETE FROM fs_user_video_comment WHERE comment_id = #{comnentId}")
    void deleteByCommentId(Long CommentId);

    @Delete("DELETE FROM fs_user_video_comment WHERE parent_id = #{parentId}")
    void deleteByParentId(String parentId);

    @Select("SELECT COUNT(1)\n" +
            "        FROM fs_user_video_comment\n" +
            "        WHERE parent_id = #{commentId}")
    Long getCommentReplyCount(@Param("commentId") String commentId);

    @Select("SELECT COUNT(1)\n" +
            "        FROM fs_user_video_comment\n" +
            "        WHERE video_id = #{videoId}")
    Integer selectCommentCountByVideos(@Param("videoId")Long videoId);
}
