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

import cn.reghao.jutil.jdk.web.db.PageList;
import cn.reghao.jutil.jdk.web.result.Result;
import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.common.auth.AuthUser;
import cn.reghao.tnb.common.auth.UserContext;
import cn.reghao.tnb.content.app.vod.model.dto.*;
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.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2024-10-31 14:02:40
 */
@Tag(name = "稿件合集接口")
@RestController
@RequestMapping("/api/content/post/album")
public class AlbumPostController {
    private final AlbumService albumService;

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

    @AuthUser
    @Operation(summary = "创建稿件合集", description = "N")
    @PostMapping(value = "/create", produces = MediaType.APPLICATION_JSON_VALUE)
    public String createAlbum(@RequestBody @Validated AlbumCreateDto albumCreateDto){
        albumService.createAlbum(albumCreateDto);
        return WebResult.success();
    }

    @AuthUser
    @Operation(summary = "添加(删除)到稿件合集", description = "N")
    @PostMapping("/action")
    public String doAlbumAction(@RequestBody @Validated AlbumActionDto albumActionDto) {
        Result result = albumService.doAlbumAction(albumActionDto);
        return WebResult.result(result);
    }

    @AuthUser
    @Operation(summary = "获取用户稿件合集的 select-list", description = "N")
    @GetMapping(value = "/kv", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getSelectOptions() {
        return WebResult.success(albumService.getSelectOptions());
    }

    @AuthUser
    @Operation(summary = "获取用户的稿件合集", description = "N")
    @GetMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getUserAlbum(@RequestParam("pn") int pageNumber) {
        long loginUser = UserContext.getUserId();
        PageList<AlbumInfo> pageList = albumService.getUserAlbums(loginUser, pageNumber);
        return WebResult.success(pageList);
    }

    @AuthUser
    @Operation(summary = "获取稿件合集中的内容", description = "N")
    @GetMapping(value = "/item", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getAlbumItems(@RequestParam(value = "albumId", required = false) Long albumId,
                                @RequestParam("pn") Integer pn) {
        String webResult = albumService.getAlbumContent(albumId, pn);
        return webResult;
    }
}
