package com.wzj.soopin.content.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wzj.soopin.content.domain.po.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

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

@InterceptorIgnore(tenantLine = "true")
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    /**
     * 根据视频ID查询评论列表
     */
    List<Comment> selectByVlogId(@Param("vlogId") String vlogId);

    /**
     * 根据父评论ID查询子评论列表
     */
    List<Comment> selectByFatherCommentId(@Param("fatherCommentId") String fatherCommentId);

    /**
     * 根据评论ID查询评论信息
     */
    Comment selectByCommentId(@Param("commentId") String commentId);

    /**
     * 根据视频ID统计评论数量
     */
    @Select("SELECT COUNT(*) FROM t_comment WHERE vlog_id = #{vlogId}")
    Integer countByVlogId(@Param("vlogId") String vlogId);

    /**
     * 根据视频ID查询评论列表
     */
    @Select("SELECT c.*, m.nickname as userNickname, m.avatar as userFace " +
            "FROM cont_comment c " +
            "LEFT JOIN ums_member m ON c.comment_user_id = m.id " +
            "WHERE c.vlog_id = #{vlogId} " +
            "ORDER BY c.create_time DESC")
    List<Map<String, Object>> selectCommentsByVlogId(@Param("vlogId") String vlogId);
}
