package com.fs.course.service.impl;

import java.util.List;
import com.fs.common.utils.DateUtils;
import com.fs.course.param.FsUserCourseCommentParam;
import com.fs.course.param.FsUserCourseCommentUParam;
import com.fs.course.vo.FsUserCourseCommentListUVO;
import com.fs.course.vo.FsUserCourseCommentListVO;
import com.fs.course.vo.FsUserCourseCommentReplyListUVO;
import com.fs.course.vo.FsUserCourseCommentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.course.mapper.FsUserCourseCommentMapper;
import com.fs.course.domain.FsUserCourseComment;
import com.fs.course.service.IFsUserCourseCommentService;

/**
 * 课堂评论Service业务层处理
 *
 * @author fs
 * @date 2024-05-15
 */
@Service
public class FsUserCourseCommentServiceImpl implements IFsUserCourseCommentService
{
    @Autowired
    private FsUserCourseCommentMapper fsUserCourseCommentMapper;

    /**
     * 查询课堂评论
     *
     * @param commentId 课堂评论主键
     * @return 课堂评论
     */
    @Override
    public FsUserCourseComment selectFsUserCourseCommentByCommentId(Long commentId)
    {
        return fsUserCourseCommentMapper.selectFsUserCourseCommentByCommentId(commentId);
    }

    /**
     * 查询课堂评论列表
     *
     * @param fsUserCourseComment 课堂评论
     * @return 课堂评论
     */
    @Override
    public List<FsUserCourseComment> selectFsUserCourseCommentList(FsUserCourseComment fsUserCourseComment)
    {
        return fsUserCourseCommentMapper.selectFsUserCourseCommentList(fsUserCourseComment);
    }

    /**
     * 新增课堂评论
     *
     * @param fsUserCourseComment 课堂评论
     * @return 结果
     */
    @Override
    public int insertFsUserCourseComment(FsUserCourseComment fsUserCourseComment)
    {
        fsUserCourseComment.setCreateTime(DateUtils.getNowDate());
        return fsUserCourseCommentMapper.insertFsUserCourseComment(fsUserCourseComment);
    }

    /**
     * 修改课堂评论
     *
     * @param fsUserCourseComment 课堂评论
     * @return 结果
     */
    @Override
    public int updateFsUserCourseComment(FsUserCourseComment fsUserCourseComment)
    {
        fsUserCourseComment.setUpdateTime(DateUtils.getNowDate());
        return fsUserCourseCommentMapper.updateFsUserCourseComment(fsUserCourseComment);
    }

    /**
     * 批量删除课堂评论
     *
     * @param commentIds 需要删除的课堂评论主键
     * @return 结果
     */
    @Override
    public int deleteFsUserCourseCommentByCommentIds(Long[] commentIds)
    {
        return fsUserCourseCommentMapper.deleteFsUserCourseCommentByCommentIds(commentIds);
    }

    /**
     * 删除课堂评论信息
     *
     * @param commentId 课堂评论主键
     * @return 结果
     */
    @Override
    public int deleteFsUserCourseCommentByCommentId(Long commentId)
    {
        return fsUserCourseCommentMapper.deleteFsUserCourseCommentByCommentId(commentId);
    }

    @Override
    public List<FsUserCourseCommentListVO> selectFsUserCourseCommentListVO(FsUserCourseCommentParam fsUserCourseComment) {
        return fsUserCourseCommentMapper.selectFsUserCourseCommentListVO(fsUserCourseComment);
    }

    @Override
    public FsUserCourseCommentVO selectFsUserCourseCommentVOByCommentId(Long commentId) {
        return fsUserCourseCommentMapper.selectFsUserCourseCommentVOByCommentId(commentId);
    }

    @Override
    public List<FsUserCourseCommentVO> selectFsUserCourseCommentAllListVO(Long pid) {
        return fsUserCourseCommentMapper.selectFsUserCourseCommentAllListVO(pid);
    }

    @Override
    public List<FsUserCourseCommentListUVO> selectFsUserCourseCommentListUVO(FsUserCourseCommentUParam param) {
        List<FsUserCourseCommentListUVO> list;
        if (param == null || param.getUserId() == null){
            list = fsUserCourseCommentMapper.selectFsUserCourseCommentListUVOAll(param);
        }else {
            list = fsUserCourseCommentMapper.selectFsUserCourseCommentListUVO(param);
        }
        return list;
    }

    @Override
    public List<FsUserCourseCommentListUVO> selectFsUserCourseCommentMyListUVO(Long userId) {
        return fsUserCourseCommentMapper.selectFsUserCourseCommentMyListUVO(userId);
    }

    @Override
    public int updateLikes(Long commentId, Integer type) {
        if (type == 1){
            return fsUserCourseCommentMapper.addLikes(commentId);
        }else {
            return fsUserCourseCommentMapper.minusLikes(commentId);
        }
    }

    @Override
    public int addComment(Long parentId) {
        return fsUserCourseCommentMapper.addComment(parentId);
    }

    public int minusComment(Long parentId) {
        return fsUserCourseCommentMapper.minusComment(parentId);
    }

    @Override
    public List<FsUserCourseCommentReplyListUVO> selectFsUserCourseCommentReplyListUVO(Long commentId) {
        return fsUserCourseCommentMapper.selectFsUserCourseCommentReplyListUVO(commentId);
    }
}
