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

import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.file.app.model.dto.OssConfigDto;
import cn.reghao.tnb.file.app.model.po.OssConfig;
import cn.reghao.tnb.file.app.service.AdminFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2026-04-27 17:04:34
 */
@Tag(name = "file 管理接口")
@RestController
@RequestMapping("/api/admin/file")
public class AdminFileController {
    private final AdminFileService adminFileService;

    public AdminFileController(AdminFileService adminFileService) {
        this.adminFileService = adminFileService;
    }

    @Operation(summary = "获取文件存储列表", description = "N")
    @GetMapping(value = "/file_store", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getFileStores() {
        List<OssConfig> list = adminFileService.getOssConfigList();
        return WebResult.success(list);
    }

    @Operation(summary = "添加文件存储", description = "N")
    @PostMapping(value = "/file_store", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public String addFileStore(@RequestBody @Validated OssConfigDto ossConfigDto) {
        adminFileService.addOssConfig(ossConfigDto);
        return WebResult.success();
    }
}
