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

import cn.reghao.jutil.jdk.result.WebResult;
import cn.reghao.oss.web.app.service.media.MediaService;
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;
import java.util.Set;

/**
 * @author reghao
 * @date 2024-02-23 09:27:28
 */
@Api(tags = "媒体接口")
@RestController
@RequestMapping("/api/oss/media")
public class MediaController {
    private final MediaService mediaService;

    public MediaController(MediaService mediaService) {
        this.mediaService = mediaService;
    }

    @ApiOperation(value = "视频转码")
    @PostMapping(value = "/convert/video/{videoFileId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String convertVideo(@PathVariable("videoFileId") String videoFileId) throws Exception {
        mediaService.convertVideo(videoFileId);
        return WebResult.success();
    }

    @ApiOperation(value = "音频转码")
    @PostMapping(value = "/convert/audio/{audioFileId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String convertAudio(@PathVariable("audioFileId") String audioFileId) throws Exception {
        mediaService.convertAudio(audioFileId);
        return WebResult.success();
    }

    @ApiOperation(value = "设置视频可见范围")
    @PostMapping(value = "/scope/video", produces = MediaType.APPLICATION_JSON_VALUE)
    public String setVideoScope(@RequestParam("videoFileId") String videoFileId,
                                @RequestParam("scope") Integer scope) {
        mediaService.setVideoScope(videoFileId, scope);
        return WebResult.success();
    }

    @ApiOperation(value = "设置音频可见范围")
    @PostMapping(value = "/scope/audio", produces = MediaType.APPLICATION_JSON_VALUE)
    public String setAudioScope(@RequestParam("audioFileId") String audioFileId,
                                @RequestParam("scope") Integer scope) {
        mediaService.setAudioScope(audioFileId, scope);
        return WebResult.success();
    }

    @ApiOperation(value = "设置图片可见范围")
    @PostMapping(value = "/scope/image", produces = MediaType.APPLICATION_JSON_VALUE)
    public String setImageScope(@RequestParam("imageFileIds") Set<String> imageFileIds,
                                @RequestParam("scope") Integer scope) {
        mediaService.setImagesScope(imageFileIds, scope);
        return WebResult.success();
    }

    @ApiOperation(value = "设置对象可见范围")
    @PostMapping(value = "/scope/object", produces = MediaType.APPLICATION_JSON_VALUE)
    public String setObjectScope(@RequestParam("scope") Integer scope,
                                @RequestParam("objectId") String objectId,
                                @RequestParam("contentType") Integer contentType) {
        mediaService.setObjectScope(scope, objectId, contentType);
        return WebResult.success();
    }

    @ApiOperation(value = "设置对象可见范围")
    @PostMapping(value = "/scope/objects", produces = MediaType.APPLICATION_JSON_VALUE)
    public String setObjectsScope(@RequestParam("scope") Integer scope,
                                  @RequestParam("objectIds") List<String> objectIds,
                                  @RequestParam("contentType") Integer contentType) {
        mediaService.setObjectsScope(scope, objectIds, contentType);
        return WebResult.success();
    }
}
