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

import cn.reghao.jutil.jdk.result.WebResult;
import cn.reghao.oss.api.dto.media.AudioInfo;
import cn.reghao.oss.api.dto.media.AudioUrl;
import cn.reghao.oss.api.dto.media.ImageUrlDto;
import cn.reghao.oss.web.app.service.media.AudioService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author reghao
 * @date 2024-02-23 09:27:21
 */
@Api(tags = "音频文件接口")
@RestController
@RequestMapping("/api/oss/media/audio")
public class AudioFileController {
    private final AudioService audioService;

    public AudioFileController(AudioService audioService) {
        this.audioService = audioService;
    }

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

    @ApiOperation(value = "获取音频文件 url")
    @GetMapping(value = "/url", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getImageUrls(@RequestParam("audioFileId") String audioFileId) {
        List<AudioUrl> list = audioService.getAudioUrls(audioFileId, 10000);
        return WebResult.success(list);
    }
}
