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

import cn.reghao.jutil.jdk.web.db.PageList;
import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.content.app.data.model.vo.AudioInfo;
import cn.reghao.tnb.content.app.data.model.vo.UserAudioCard;
import cn.reghao.tnb.content.app.data.service.AudioService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2023-10-12 13:49:11
 */
@Tag(name = "音频接口")
@RestController
@RequestMapping("/api/content/audio")
public class AudioController {
    private final AudioService audioService;
    
    public AudioController(AudioService audioService) {
        this.audioService = audioService;
    }
    
    @Operation(summary = "获取音频列表")
    @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getAudios(@RequestParam("page") int page) {
        PageList<UserAudioCard> pageList = audioService.getAudios(page);
        return WebResult.success(pageList);
    }

    @Operation(summary = "获取用户音频列表")
    @GetMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getUserAudios(@RequestParam("page") int page, @RequestParam("userId") long userId) {
        PageList<UserAudioCard> pageList = audioService.getPageByUserId(userId, page);
        return WebResult.success(pageList);
    }
    
    @Operation(summary = "获取音频详细信息")
    @GetMapping(value = "/{audioId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getAudioInfo(@PathVariable("audioId") String audioId) {
        AudioInfo audioInfo = audioService.getAudioInfo(audioId);
        return WebResult.success(audioInfo);
    }
}
