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.ModelImageCommentRes;
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
import com.mcwl.resource.service.ModelImageCommentLikeService;
import com.mcwl.resource.service.ModelImageCommentService;
import com.mcwl.resource.service.ModelImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

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

/**
 * 图片评论
 */
@Api(tags = "图片评论")
@RestController
@RequestMapping("/imageComment")
@RequiredArgsConstructor
public class ModelImageCommentController {

    private final ModelImageService modelImageService;

    private final ModelImageCommentLikeService modelImageCommentLikeService;

    private final ModelImageCommentService modelImageCommentService;


    /**
     * 图片评论发布
     */
    @ApiOperation(value = "图片评论发布")
    @PostMapping("/comment")
    public R<Object> comment(@Valid @RequestBody ModelImageCommentRes modelImageCommentRes) {
        modelImageCommentService.comment(modelImageCommentRes);
        return R.ok();
    }

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

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

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

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


}
