package cn.reghao.tnb.content.app.vod.controller;

import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.common.auth.AuthUser;
import cn.reghao.tnb.common.auth.UserContext;
import cn.reghao.tnb.common.db.PageScroll;
import cn.reghao.tnb.content.api.dto.VideoUrls;
import cn.reghao.tnb.content.api.dto.VideoRecordCard;
import cn.reghao.tnb.content.app.vod.service.VideoPlayService;
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.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2021-12-30 10:12:13
 */
@Slf4j
@Tag(name = "视频播放接口")
@RestController
@RequestMapping("/api/content/video")
public class VideoPlayController {
    private final VideoPlayService videoPlayService;

    public VideoPlayController(VideoPlayService videoPlayService) {
        this.videoPlayService = videoPlayService;
    }

    @Operation(summary = "获取视频播放的 URL", description = "N")
    @GetMapping(value = "/url/{videoId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String videoUrl1(@PathVariable("videoId") String videoId) {
        VideoUrls videoUrls = videoPlayService.getVideoPlayData(videoId);
        return WebResult.success(videoUrls);
    }

    @AuthUser
    @Operation(summary = "获取某个用户的视频播放记录", description = "N")
    @GetMapping(value = "/visit", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getVisitedVideo(@RequestParam("nextId") long nextId) {
        long userId = UserContext.getUserId();
        PageScroll<VideoRecordCard> pager = videoPlayService.getPlayRecord(nextId, userId);
        return WebResult.success(pager);
    }
}
