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.common.auth.AuthUser;
import cn.reghao.tnb.content.app.data.model.dto.AudioPublishSbt;
import cn.reghao.tnb.content.app.data.model.dto.AudioScopeUpdate;
import cn.reghao.tnb.content.app.data.model.vo.UserAudioCard;
import cn.reghao.tnb.content.app.data.service.AudioPostService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2023-01-29 10:12:06
 */
@Tag(name = "音频贴接口")
@RestController
@RequestMapping("/api/content/post/audio")
public class AudioPostController {
    private final AudioPostService audioPostService;

    public AudioPostController(AudioPostService audioPostService) {
        this.audioPostService = audioPostService;
    }

    @AuthUser
    @Operation(summary = "添加音频贴")
    @PostMapping("")
    public String submitAudioPost(@RequestBody @Validated AudioPublishSbt audioPublishSbt) {
        audioPostService.submit(audioPublishSbt);
        return WebResult.success();
    }

    @AuthUser
    @Operation(summary = "更新音频贴可见范围")
    @PostMapping("/update/scope")
    public String updateAudioScope(@RequestBody @Validated AudioScopeUpdate audioScopeUpdate) {
        audioPostService.updateAudioScope(audioScopeUpdate);
        return WebResult.success();
    }

    @AuthUser
    @Operation(summary = "删除音频贴")
    @DeleteMapping("/{audioId}")
    public String deleteAudioPost(@PathVariable("audioId") String audioId) {
        audioPostService.deleteAudio(audioId);
        return WebResult.success();
    }

    @AuthUser
    @Operation(summary = "获取音频贴")
    @GetMapping("/{audioId}")
    public String getAudioPost(@PathVariable("audioId") String audioId) {
        UserAudioCard userAudioCard = audioPostService.getAudioInfo(audioId);
        return WebResult.success(userAudioCard);
    }

    @AuthUser
    @Operation(summary = "获取音频贴列表")
    @GetMapping("")
    public String getAudioPosts(@RequestParam("page") int page) {
        PageList<UserAudioCard> pageList = audioPostService.getPageByUserId(page);
        return WebResult.success(pageList);
    }
}
