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/file")
public class FileUploadController {

    @Resource
    private FileUploadApi fileUploadApi;
    @ApiOperation("内部上传单个文件（创建人为当前用户）")
    @PostMapping("/upload")
    public SingleResponse<FileInfoCO> uploadInternal(
            @ApiParam("上传文件") @RequestParam("file") MultipartFile file) {
        return fileUploadApi.uploadInternal(file);
    }

    @ApiOperation("内部批量上传文件（创建人为当前用户）")
    @PostMapping("/upload/batch")
    public SingleResponse<List<FileInfoCO>> uploadInternalBatch(
            @ApiParam("上传文件列表") @RequestParam("files") List<MultipartFile> files) {
        return fileUploadApi.uploadInternalBatch(files);
    }
}
