package com.playlet.web.controller.app;

import com.github.pagehelper.PageInfo;
import com.playlet.common.core.domain.Result;
import com.playlet.system.domain.PublicCommentStar;
import com.playlet.system.domain.PublicDetailComment;
import com.playlet.web.service.app.PublicDetailCommentAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Slf4j
@Api(tags = "公众号*用户评论接口")
@RestController
@RequestMapping(value = "/app/public/comment")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PublicDetailCommentAppController {

    private final PublicDetailCommentAppService detailCommentAppService;

    @ResponseBody
    @PostMapping("/add")
    @ApiOperation(value = "新增用户评论")
    public Result<PublicDetailComment> add(@RequestBody PublicDetailComment detailComment) {
        detailComment.setCreateTime(new Date());
        detailCommentAppService.add(detailComment);
        return Result.success(detailComment);
    }

    @ResponseBody
    @PostMapping("/delete")
    @ApiOperation(value = "删除用户评论")
    public Result<String> delete(@RequestBody PublicDetailComment detailComment) {
        detailCommentAppService.delete(detailComment);
        return Result.success();
    }

    @ResponseBody
    @PostMapping("/update")
    @ApiOperation(value = "更新用户评论(后续点赞使用)")
    public Result<String> update(@RequestBody PublicDetailComment detailComment) {
        detailCommentAppService.update(detailComment);
        return Result.success();
    }

    @ResponseBody
    @PostMapping("/query")
    @ApiOperation(value = "查询当前文章评论,需传文章id")
    public Result<PageInfo<PublicDetailComment>> query(@RequestBody PublicDetailComment detailComment,
                                                       @RequestParam(value = "pageNum") Integer pageNum,
                                                       @RequestParam(value = "pageSize") Integer pageSize) {

        return Result.success(detailCommentAppService.query(detailComment, pageNum, pageSize));
    }

    @ResponseBody
    @PostMapping("/getTopComment")
    @ApiOperation(value = "获取置顶评论")
    public Result<PublicDetailComment> getTopComment(@RequestBody PublicDetailComment detailComment) {
        return Result.success(detailCommentAppService.getTopComment(detailComment));
    }

    @ResponseBody
    @PostMapping("/start")
    @ApiOperation(value = "点赞用户评论")
    public Result<String> start(@RequestBody PublicCommentStar publicCommentStar) {
        detailCommentAppService.star(publicCommentStar);
        return Result.success();
    }

    @ResponseBody
    @PostMapping("/cancelStar")
    @ApiOperation(value = "取消点赞用户评论")
    public Result<String> cancelStar(@RequestBody PublicCommentStar publicCommentStar) {
        detailCommentAppService.cancelStar(publicCommentStar);
        return Result.success();
    }

}
