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.content.app.vod.model.vo.DownloadUrl;
import cn.reghao.tnb.content.app.vod.service.VideoService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2022-02-08 15:26:14
 */
@Tag(name = "视频数据接口")
@RestController
@RequestMapping("/api/content/video")
public class VideoController {
    private final VideoService videoService;

    public VideoController(VideoService videoService) {
        this.videoService = videoService;
    }

    @Operation(summary = "点赞视频", description = "N")
    @PostMapping("/thumb/{videoId}")
    public String thumbUpVideo(@PathVariable("videoId") String videoId) {
        videoService.thumbVideo(videoId);
        return WebResult.success();
    }

    @Operation(summary = "分享视频", description = "N")
    @PostMapping("/share/{videoId}")
    public String shareVideo(@PathVariable("videoId") String videoId) {
        String shortUrl = videoService.getShareLink(videoId);
        return WebResult.success(shortUrl);
    }

    @AuthUser
    @Operation(summary = "下载视频", description = "N")
    @GetMapping("/download/{videoId}")
    public String getDownloadUrl(@PathVariable("videoId") String videoId) {
        DownloadUrl downloadUrl = videoService.downloadVideo(videoId);
        if (downloadUrl != null) {
            return WebResult.success(downloadUrl);
        } else {
            return WebResult.failWithMsg("视频文件不存在");
        }
    }
}
