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

import cn.reghao.jutil.jdk.web.db.PageList;
import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.common.auth.AuthUser;
import cn.reghao.tnb.content.app.vod.model.po.PostAlbum;
import cn.reghao.tnb.content.app.vod.model.vo.AlbumInfo;
import cn.reghao.tnb.content.app.vod.service.AlbumService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.ibatis.annotations.Param;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2024-11-06 16:13:01
 */
@Tag(name = "稿件合集接口")
@RestController
@RequestMapping("/api/content/album")
public class AlbumQueryController {
    private final AlbumService albumService;

    public AlbumQueryController(AlbumService albumService) {
        this.albumService = albumService;
    }

    @AuthUser
    @Operation(summary = "获取用户稿件合集列表", description = "N")
    @GetMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getUserAlbums(@RequestParam("userId") String userIdStr, @Param("pn") int pn) {
        PageList<AlbumInfo> pageList = albumService.getUserAlbums(userIdStr, pn);
        return WebResult.success(pageList);
    }

    @Operation(summary = "获取播放列表", description = "N")
    @GetMapping(value = "/playlist", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getPlaylist(@RequestParam("pn") int pn) {
        PageList<PostAlbum> pageList = albumService.getPlaylist(pn);
        return WebResult.success(pageList);
    }

    @Operation(summary = "获取播放列表内容", description = "N")
    @GetMapping(value = "/playlist/{albumId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getPlaylistItems(@PathVariable("albumId") long albumId) {
        String webResult = albumService.getPlaylistItems(albumId);
        return webResult;
    }
}
