package org.springblade.file.feign;

import jakarta.validation.constraints.NotNull;
import org.springblade.core.tool.api.R;
import org.springblade.file.config.FeignFileUploadClientConfig;
import org.springblade.file.pojo.entity.Attachment;
import org.springblade.file.pojo.vo.TempFileUrlVO;
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.List;

/**
 * @author bfhuange
 * @date 2024/10/21
 */
@FeignClient(
        value = "blade-file",
        fallback = IFileClientFallback.class,
        configuration = FeignFileUploadClientConfig.class
)
public interface IFileUploadClient {

    String API_PREFIX = "/feign/client/file";
    String UPLOAD = API_PREFIX + "/ossUpload";
    String UPLOAD_TEMP = API_PREFIX + "/ossUploadTemp";

    /**
     *  文件上传
     * @param files
     * @return
     */
    @PostMapping(value = UPLOAD, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    R<List<Attachment>> ossUpload(@RequestPart("files") MultipartFile[] files);

    /**
     *  上传临时文件，不保存到附件表，过期后自动删除
     * @param file
     * @param expires 过期时间，单位天，过期后自动删除
     * @return
     */
    @PostMapping(value = UPLOAD_TEMP, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    R<TempFileUrlVO> ossUploadTemp(@RequestPart("file") MultipartFile file, @NotNull(message = "过期时间不能为空") @RequestParam(name = "expires", required = false) Integer expires);
}
