package com.xueyi.file.api.feign;

import com.xueyi.common.core.constant.basic.ServiceConstants;
import com.xueyi.common.core.web.result.R;
import com.xueyi.file.api.domain.SysFile;
import com.xueyi.file.api.feign.factory.RemoteFileFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
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 xueyi
 */
@FeignClient(contextId = "remoteFileService", value = ServiceConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class)
public interface RemoteFileService {

    /**
     * 上传文件
     *
     * @param file 文件信息
     * @return 结果
     */
    @PostMapping(value = "/inner/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @Async
    R<SysFile> upload(@RequestPart(value = "file") MultipartFile file, @RequestParam (value = "extension") String extension, @RequestParam (value = "fileUuid") String fileUuid);

    @PostMapping(value = "/inner/uploadNoAsync", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    R<SysFile> uploadNoAsync(@RequestPart(value = "file") MultipartFile file, @RequestParam (value = "extension") String extension, @RequestParam (value = "fileUuid") String fileUuid);

    @PostMapping(value = "/inner/uploadFace", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    R<SysFile> uploadFace(@RequestPart(value = "file") MultipartFile file);

    @PostMapping(value = "/inner/upload-temp", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    R<SysFile> uploadTemp(@RequestPart(value = "file") MultipartFile file);

    /**
     * 上传pdf文件
     *
     * @param file 文件信息
     * @return 结果
     */
    @PostMapping(value = "/inner/uploadpdf", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @Async
    R<List<SysFile>> uploadPdf(@RequestPart(value = "file") MultipartFile file, @RequestParam (value = "fileUuid") String fileUuid);

    /**
     * 删除文件
     *
     * @param url 文件地址
     * @return 结果
     */
    @DeleteMapping(value = "/inner/delete/{url}")
    R<Boolean> delete(@PathVariable("url") String url);
}
