package com.mcwl.web.controller.resource;

import com.mcwl.common.annotation.RepeatSubmit;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.domain.R;
import com.mcwl.resource.domain.dto.ModelCommentRes;
import com.mcwl.resource.domain.vo.ModelCommentVo;
import com.mcwl.resource.service.ModelCommentLikeService;
import com.mcwl.resource.service.ModelCommentService;
import com.mcwl.resource.service.ModelLikeService;
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("/ModelComment")
@RestController
public class ModelCommentController {

    @Autowired
    private ModelLikeService modelLikeService;
    @Autowired
    private ModelCommentService modelCommentService;
    @Autowired
    private ModelCommentLikeService modelCommentLikeService;


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


    /**
     * 模型评论发布
     */
    @ApiOperation(value = "模型评论发布")
    @PostMapping("/comment")
    public R<Object> comment(@Valid @RequestBody ModelCommentRes modelCommentRes) {
        modelCommentService.comment(modelCommentRes);
        return R.ok();
    }

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


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


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

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

}
