package com.jeeplus.common.feign;

import com.jeeplus.common.constant.AppNameConstants;
import com.jeeplus.common.factory.FileApiFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@FeignClient(contextId = "fileApi", name = AppNameConstants.APP_FILE_SERVICE, fallbackFactory = FileApiFallbackFactory.class)
public interface IFileApi {

    /**
     * 获取文件网络地址
     *
     * @return
     * @throws IOException
     * @throws IllegalStateException
     */
    @GetMapping("/file/download")
    void download(@RequestParam("uploadPath") String uploadPath, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "response", required = false) HttpServletResponse response) throws Exception;

    /**
     * 上传文件
     *
     * @return
     * @throws IOException
     */
    @RequestMapping("/file/upload")
    ResponseEntity upload(@RequestParam(value = "request", required = false) HttpServletRequest request, @RequestParam(value = "file", required = false) MultipartFile file);
}
