package com.yd.oss.api.controller;

import com.yd.common.result.Result;
import com.yd.oss.api.service.ApiChunkedUploadContextService;
import com.yd.oss.feign.client.ApiChunkedUploadContextFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.Map;

/**
 * 分片上传上下文信息
 * （一个任务上传文件信息拆分成多个ETag上传存储，任务执行完毕，阿里云合并ETag列表为完整的文件信息）
 * @author zxm
 * @since 2026-08-05
 */
@Slf4j
@RestController
@RequestMapping("/chunkedUploadContext")
@Validated
public class ApiChunkedUploadContextController implements ApiChunkedUploadContextFeignClient {

    @Resource
    private ApiChunkedUploadContextService apiChunkedUploadContextService;

    /**
     * 上传单个分片
     */
    public Result<Void> uploadChunk(String taskId,Integer chunkIndex,
                                    MultipartFile chunk,String projectBizId,
                                    String source) {
        apiChunkedUploadContextService.uploadChunk(taskId, chunkIndex, chunk,projectBizId,source);
        return Result.success();
    }

    /**
     * 完成分片上传（合并）
     */
    public Result<Map<String, Object>> finishChunks(String taskId,
                                                    String projectBizId) {
        return apiChunkedUploadContextService.finishChunks(taskId,projectBizId);
    }
}
