package com.mcwl.web.controller.resource;

import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.domain.R;
import com.mcwl.resource.domain.dto.WorkFlowCommentRes;
import com.mcwl.resource.domain.vo.WorkFlowCommentVo;
import com.mcwl.resource.service.WorkFlowCommentLikeService;
import com.mcwl.resource.service.WorkFlowCommentService;
import com.mcwl.resource.service.WorkFlowLikeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 工作流评论
 *
 * @Author：ChenYan
 * @Project：McWl
 * @Package：com.mcwl.web.controller.resource
 * @Filename：ModelCommentcontroller
 * @Description TODO
 * @Date：2025/1/12 11:36
 */
@Api(tags = "工作流评论")
@RequestMapping("/WorkFlowComment")
@RestController
public class WorkFlowCommentController {

    @Autowired
    private WorkFlowLikeService workFlowLikeService;
    @Autowired
    private WorkFlowCommentService workFlowCommentService;
    @Autowired
    private WorkFlowCommentLikeService workFlowCommentLikeService;


    /**
     * 工作流点赞/取消
     */
    @ApiOperation(value = "工作流点赞/取消")
    @GetMapping("/like")
    public R<Object> like(@Valid
                           @NotNull(message = "模型id不能为空")
                           @ApiParam(value = "模型id", required = true)
                           Long workFlowId) {
        workFlowLikeService.like(workFlowId);
        return R.ok();
    }


    /**
     * 工作流评论发布
     */
    @ApiOperation(value = "工作流评论发布")
    @PostMapping("/comment")
    public R<Object> comment(@Valid
                              @RequestBody
                              WorkFlowCommentRes workFlowCommentRes) {
        workFlowCommentService.comment(workFlowCommentRes);
        return R.ok();
    }

    /**
     * 工作流评论点赞/取消
     */
    @ApiOperation(value = "工作流评论点赞/取消")
    @GetMapping("/commentLike")
    public R<Object> commentLike(@Valid
                                  @NotNull(message = "评论id不能为空")
                                  @ApiParam(value = "评论id", required = true)
                                  Long commentId) {
        workFlowCommentLikeService.like(commentId);
        return R.ok();
    }


    /**
     * 获取工作流评论
     */
    @ApiOperation(value = "获取工作流评论")
    @GetMapping("/getComment")
    public R<List<WorkFlowCommentVo>> getComment(@Valid
                                 @NotNull(message = "模型id不能为空")
                                 @ApiParam(value = "模型id", required = true)
                                 Long commentId,
                                                 @Valid
                                 @NotNull(message = "排序方式不能为空")
                                 @ApiParam(value = "排序方式 0最热 1最新", required = true)
                                 Integer sortType) {
        List<WorkFlowCommentVo> modelCommentList = workFlowCommentService.getComment(commentId, sortType);
        return R.ok(modelCommentList);
    }


    /**
     * 删除工作流评论
     */
    @ApiOperation(value = "删除工作流评论")
    @GetMapping("/commentDelete")
    public R<Object> commentDelete(@Valid
                                    @NotNull(message = "评论id不能为空")
                                    @ApiParam(value = "评论id", required = true)
                                    Long commentId) {
        workFlowCommentService.removeById(commentId);
        return R.ok();
    }

    /**
     * 获取工作流评论数量
     */
    @ApiOperation(value = "获取工作流评论数量")
    @GetMapping("/commentCount")
    public R<Integer> getCommentCount(@Valid
                                      @NotNull(message = "工作流id不能为空")
                                      @ApiParam(value = "工作流id", required = true)
                                      Long workFlowId) {
        Integer commentCount = workFlowCommentService.getCommentCount(workFlowId);
        return R.ok(commentCount);
    }

}
