package cn.reghao.tnb.file.app.controller;

import cn.reghao.jutil.web.WebResult;
import cn.reghao.oss.sdk.model.dto.ServerInfo;
import cn.reghao.tnb.common.auth.AuthUser;
import cn.reghao.tnb.file.app.rpc.StoreServiceWrapperRouter;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author reghao
 * @date 2024-04-19 20:47:14
 */
@Tag(name = "OSS 接口")
@RestController
@RequestMapping("/api/file/oss")
public class OssController {
    private final StoreServiceWrapperRouter storeServiceWrapperRouter;

    public OssController(StoreServiceWrapperRouter storeServiceWrapperRouter) {
        this.storeServiceWrapperRouter = storeServiceWrapperRouter;
    }

    @AuthUser
    @Operation(summary = "获取图片上传 token", description = "N")
    @PostMapping(value = "/serverinfo/image", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getImageChannelInfo() throws Exception {
        ServerInfo serverInfo = storeServiceWrapperRouter.getUploadStore(104);
        return WebResult.success(serverInfo);
    }

    @AuthUser
    @Operation(summary = "获取照片上传 token", description = "N")
    @PostMapping(value = "/serverinfo/photo", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getPhotoChannelInfo() throws Exception {
        ServerInfo serverInfo = storeServiceWrapperRouter.getUploadStore(105);
        return WebResult.success(serverInfo);
    }

    @AuthUser
    @Operation(summary = "获取视频上传 token", description = "N")
    @PostMapping(value = "/serverinfo/video", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getVideoChannelInfo() throws Exception {
        ServerInfo serverInfo = storeServiceWrapperRouter.getUploadStore(101);
        return WebResult.success(serverInfo);
    }

    @AuthUser
    @Operation(summary = "获取文件上传 token", description = "N")
    @PostMapping(value = "/serverinfo/file", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getFileChannelInfo() throws Exception {
        ServerInfo serverInfo = storeServiceWrapperRouter.getUploadStore(114);
        return WebResult.success(serverInfo);
    }
}
