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

import cn.reghao.jutil.jdk.web.result.Result;
import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.content.api.dto.DanmakuSbtDto;
import cn.reghao.tnb.search.app.comment.service.DanmakuService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2021-12-06 19:12:13
 */
@Tag(name = "弹幕接口")
@RestController
@RequestMapping("/api/comment/danmaku")
public class DanmakuController {
    private final DanmakuService danmakuService;

    public DanmakuController(DanmakuService danmakuService) {
        this.danmakuService = danmakuService;
    }

    @Operation(summary = "发送视频弹幕", description = "N")
    @PostMapping("/v3/")
    public String submitDanmaku(@RequestBody @Validated DanmakuSbtDto danmakuSbtDto) {
        Result result = danmakuService.submit(danmakuSbtDto);
        return WebResult.result(result);
    }

    @Operation(summary = "获取视频弹幕", description = "N")
    @GetMapping(value = "/v3/", produces = MediaType.APPLICATION_JSON_VALUE)
    public String danmakuList(@RequestParam("id") String videoId, @RequestParam("max") int max) {
        List<List<Object>> lists = danmakuService.getByVideoIdAndSize(videoId, 1000);
        return WebResult.success(lists);
    }
}
