package com.yd.oss.feign.client;

import com.yd.common.result.Result;
import com.yd.oss.feign.fallback.ApiChunkedUploadContextFeignFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import java.util.Map;

/**
 * 分片上传上下文信息Feign客户端
 */
@FeignClient(name = "yd-oss-api", path = "/oss/api/chunkedUploadContext", fallbackFactory = ApiChunkedUploadContextFeignFallbackFactory.class)
public interface ApiChunkedUploadContextFeignClient {

    /**
     * 上传单个分片
     * @param chunk
     * @param taskId
     * @param chunkIndex
     * @param projectBizId
     * @param source
     * @return
     */
    @PostMapping(value = "/uploadChunk", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    Result<Void> uploadChunk(
            @RequestPart("chunk") MultipartFile chunk,
            @RequestParam("taskId") String taskId,
            @RequestParam("chunkIndex") Integer chunkIndex,
            @RequestParam("projectBizId") String projectBizId,
            @RequestParam("source") String source
    );

    /**
     * 完成分片上传（合并）
     */
    @PostMapping("/finishChunks")
    Result<Map<String, Object>> finishChunks(
            @RequestParam("taskId") String taskId,
            @RequestParam("projectBizId") String projectBizId
    );
}
