package cn.reghao.tnb.search.app.comment.controller;

import cn.reghao.jutil.jdk.web.db.PageList;
import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.common.auth.AuthUser;
import cn.reghao.tnb.search.app.comment.model.dto.CommentSbtDto;
import cn.reghao.tnb.search.app.comment.model.vo.UserReply;
import cn.reghao.tnb.search.app.comment.service.CommentService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2022-03-06 21:25:44
 */
@Slf4j
@Tag(name = "评论接口")
@RestController
@RequestMapping("/api/comment")
public class CommentController {
    private final CommentService commentService;

    public CommentController(CommentService commentService) {
        this.commentService = commentService;
    }

    @AuthUser
    @Operation(summary = "发送视频评论", description = "N")
    @PostMapping("/video")
    public String submitComment(@RequestBody @Validated CommentSbtDto commentSbtDto) {
        commentService.saveComment(commentSbtDto);
        return WebResult.success();
    }

    @Operation(summary = "获取视频评论", description = "N")
    @GetMapping(value = "/video", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getUserComment(@RequestParam("videoId") String videoId, @RequestParam("pn") int pageNumber) {
        PageList<UserReply> pageList = commentService.getUserComment(videoId, pageNumber);
        return WebResult.success(pageList);
    }

    @Operation(summary = "获取评论的子评论", description = "N")
    @GetMapping(value = "/video/child", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getChildComment(@RequestParam("commentId") long commentId, @RequestParam("pn") int pageNumber) {
        PageList<UserReply> pageList = commentService.getChildComment(commentId, pageNumber);
        return WebResult.success(pageList);
    }
}
