package com.mcwl.web.controller.communityCenter;

import com.mcwl.common.core.controller.BaseController;
import com.mcwl.common.core.domain.R;
import com.mcwl.communityCenter.domain.dto.CommentDelRes;
import com.mcwl.communityCenter.domain.dto.CommentDetailRes;
import com.mcwl.communityCenter.domain.dto.CommentRes;
import com.mcwl.communityCenter.domain.dto.PublishCommentLikeRes;
import com.mcwl.communityCenter.domain.vo.CommentVo;
import com.mcwl.communityCenter.service.PublishCommentLikeService;
import com.mcwl.communityCenter.service.PublishCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 社群评论
 */
@Api(tags = "社群评论")
@RequestMapping("publishComment")
@RestController
@RequiredArgsConstructor

public class PublishCommentController extends BaseController {

    private final PublishCommentService publishCommentService;
    private final PublishCommentLikeService publishCommentLikeService;

    /**
     * 获取评论
     */
    @ApiOperation(value = "获取评论")
    @PostMapping("/list")
    public R<List<CommentVo>> list(@RequestBody @Valid CommentDetailRes commentDetailRes) {

        return publishCommentService.getComment(commentDetailRes);
    }


    /**
     * 添加发布评论
     *
     * @param commentRes 评论请求参数
     * @return
     */
    @ApiOperation(value = "添加发布评论")
    @PostMapping("/save")
    public R<Object> save(@RequestBody @Valid CommentRes commentRes) {

        return publishCommentService.addComment(commentRes);
    }


//    /**
//     * 获取评论详情
//     *
//     * @param commentDetailRes 评论详情请求参数
//     * @return 评论详情
//     */
//    @ApiOperation(value = "获取评论详情")
//    @PostMapping("/detail")
//    public R<List<CommentVo>> getComment(@RequestBody @Valid CommentDetailRes commentDetailRes) {
//
//        return publishCommentService.getComment(commentDetailRes);
//    }


    /**
     * 点赞或取消点赞评论
     */
    @ApiOperation(value = "点赞或取消点赞评论")
    @PostMapping("/like")
    public R<Integer> like(@RequestBody @Valid PublishCommentLikeRes publishCommentLikeRes) {

        return publishCommentLikeService.like(publishCommentLikeRes);
    }


    @ApiOperation(value = "删除评论")
    @PostMapping("/delete")
    public R<Object> delete(@RequestBody @Valid CommentDelRes commentDelRes) {

        return publishCommentService.removeCommentById(commentDelRes);
    }

}
