package cn.reghao.oss.console.app.controller;

import cn.reghao.jutil.jdk.result.WebResult;
import cn.reghao.oss.console.app.model.dto.GetImageUrls;
import cn.reghao.oss.console.app.rpc.MediaRpcService;
import cn.reghao.oss.storeapi.dto.media.AudioInfo;
import cn.reghao.oss.storeapi.dto.media.ConvertedImageInfo;
import cn.reghao.oss.storeapi.dto.media.ImageInfo;
import cn.reghao.oss.storeapi.dto.media.VideoInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2024-02-23 09:05:58
 */
@Api(tags = "视频文件接口")
@RestController
@RequestMapping("/api/oss/media")
public class MediaController {
    private final MediaRpcService mediaRpcService;

    public MediaController(MediaRpcService mediaRpcService) {
        this.mediaRpcService = mediaRpcService;
    }

    @ApiOperation(value = "获取视频文件信息")
    @GetMapping(value = "/video/info", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getVideoInfo(@RequestParam("channelId") Integer channelId,
                               @RequestParam("videoFileId") String videoFileId) throws Exception {
        VideoInfo videoInfo = mediaRpcService.getVideoInfo(channelId, videoFileId);
        return WebResult.success(videoInfo);
    }

    @ApiOperation(value = "获取图片文件信息")
    @PostMapping(value = "/image/info", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getImagesInfo(GetImageUrls getImageUrls) throws Exception {
        List<ImageInfo> list = mediaRpcService.getImagesInfo(getImageUrls.getChannelId(), getImageUrls.getImageFileIds());
        return WebResult.success(list);
    }

    @ApiOperation(value = "获取 webp 图片文件信息")
    @PostMapping(value = "/image/webp", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getWebpInfo(GetImageUrls getImageUrls) throws Exception {
        List<ConvertedImageInfo> list = mediaRpcService.getWebpInfo(getImageUrls.getChannelId(), getImageUrls.getImageFileIds());
        return WebResult.success(list);
    }

    @ApiOperation(value = "获取音频文件信息")
    @GetMapping(value = "/auduio/info", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getAudioInfo(@RequestParam("channelId") Integer channelId,
                               @RequestParam("audioFileId") String audioFileId) throws Exception {
        AudioInfo audioInfo = mediaRpcService.getAudioInfo(channelId, audioFileId);
        return WebResult.success(audioInfo);
    }
}
