package org.qinan.safetyeval.adapter.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.qinan.safetyeval.client.api.FileUploadApi;
import org.qinan.safetyeval.client.co.FileInfoCO;
import org.qinan.safetyeval.client.dto.SingleResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件上传适配层（Controller）
 * <p>
 * 区分公开上传（创建人默认 system）与内部上传（创建人为当前登录用户）。
 * 上传完成后自动同步元信息到 filestorage 表。
 * </p>
 *
 * @author safety-eval
 */
@Api(tags = "文件上传")
@RestController
@RequestMapping("/safetyEval/test/file")
public class FileUploadPublicController {

    @Resource
    private FileUploadApi fileUploadApi;

    // ==================== 公开上传 ====================

    @ApiOperation("测试接口")
    @GetMapping("/helloword")
    public SingleResponse<String> helloword() {
        return SingleResponse.success("helloword");
    }

    @ApiOperation("公开上传单个文件（创建人默认 system）")
    @PostMapping("/upload")
    public SingleResponse<FileInfoCO> uploadPublic(
            @ApiParam("上传文件") @RequestParam("file") MultipartFile file) {
        return fileUploadApi.uploadPublic(file);
    }

    @ApiOperation("公开批量上传文件（创建人默认 system）")
    @PostMapping("/upload/batch")
    public SingleResponse<List<FileInfoCO>> uploadPublicBatch(
            @ApiParam("上传文件列表") @RequestParam("files") List<MultipartFile> files) {
        return fileUploadApi.uploadPublicBatch(files);
    }
}
