package com.chushang.oss.feign;

import com.chushang.common.core.constant.SecurityConstants;
import com.chushang.common.core.web.Result;
import com.chushang.oss.constants.OssConstants;
import com.chushang.oss.entity.dto.UploadBytesDTO;
import com.chushang.oss.entity.dto.UploadFileDTO;
import com.chushang.oss.entity.dto.UploadStreamDTO;
import com.chushang.oss.entity.vo.FileSourceVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Set;

@FeignClient(contextId = "ossFeign",
        value = OssConstants.OSS_SERVICE,
        path = OssConstants.APPLICATION_CONTENT_PATH + "/remote/file"
)
public interface RemoteOssService {

    @PostMapping(value = "/upload")
    Result<List<FileSourceVo>> uploadFile(@RequestPart(name = "files") MultipartFile[] files,
                                            @RequestParam(value = "ocrType", required = false) String ocrType,
                                            @RequestParam(value = "sealFlag", required = false, defaultValue= "false") Boolean sealFlag,
                                            @RequestParam(value = "formats", required = false) String formats,
                                            @RequestParam(value = "fileType", required = false) String fileType,
                                            @RequestHeader(SecurityConstants.FROM_SOURCE) String source);


    @PostMapping(value = "/uploadqccode")
    Result<String> uploadQcCode(@RequestHeader(SecurityConstants.FROM_SOURCE) String source) throws Exception;

    /**
     * 通过 文件字节上传,
     * 需要文件名称, 文件路径,
     * 不需要 做ocr, 需要做 水印添加
     * @param bytes 字节
     *
     */
    @PostMapping(value = "/upload/bytes")
    Result<List<FileSourceVo>> uploadBytes(@RequestBody UploadBytesDTO uploadBytes,
                                            @RequestParam(value = "fileName") String fileName,
                                            @RequestParam(value = "sealFlag", required = false, defaultValue= "false") Boolean sealFlag,
                                            @RequestParam(value = "formats", required = false) String formats,
                                            @RequestParam(value = "fileType", required = false) String fileType,
                                            @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/file/{fid}")
    Result<byte[]> getFile(@PathVariable(name = "fid") String fid,@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @DeleteMapping(value = "/del/{fid}")

    Result<String> delFile(@PathVariable(name = "fid") String fid, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
    @PostMapping(value = "/del/batch")
    Result<String> delFile(@RequestBody Set<String> fids,
                           @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 通过 文件字节上传,
     * 需要文件名称, 文件路径,
     * 不需要 做ocr, 需要做 水印添加
     * @param uploadStream is
     *
     */
    @PostMapping(value = "/upload/stream")
    Result<List<FileSourceVo>> uploadStream(@RequestBody UploadStreamDTO uploadStream,
                                            @RequestParam(value = "fileName") String fileName,
                                            @RequestParam(value = "sealFlag", required = false, defaultValue= "false") Boolean sealFlag,
                                            @RequestParam(value = "formats", required = false) String formats,
                                            @RequestParam(value = "fileType", required = false) String fileType,
                                            @RequestHeader(SecurityConstants.FROM_SOURCE) String source);


}
