package com.fjhx.feign;

import com.fjhx.constants.ClientConstant;
import com.fjhx.entity.FileInfo;
import org.springblade.core.tool.api.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * File Feign接口类
 */
@FeignClient(value = "service-file")
public interface IFileClient {

    String BINDING_FILE = ClientConstant.API_PREFIX + "/bindingFile";

    String AGAIN_BINDING_FILE = ClientConstant.API_PREFIX + "/againBindingFile";

    String RELIEVE_BINDING_FILE = ClientConstant.API_PREFIX + "/relieveBindingFile";

    String GET_FILE_INFO = ClientConstant.API_PREFIX + "/getFileInfo";

    String UPLOAD_FILE = ClientConstant.API_PREFIX + "/uploadFile";

    /**
     * 文件绑定业务id
     *
     * @param businessId   业务id
     * @param businessType 业务类型
     * @param paramList    文件信息
     */
    @PostMapping(BINDING_FILE)
    R bindingFile(@RequestParam("applicationName") String applicationName,
                  @RequestParam("businessId") Long businessId,
                  @RequestParam("businessType") Integer businessType,
                  @RequestBody List<FileInfo> paramList);

    /**
     * 修改文件绑定信息
     *
     * @param businessId   业务id
     * @param businessType 业务类型
     * @param paramList    文件信息
     */
    @PostMapping(AGAIN_BINDING_FILE)
    R againBindingFile(@RequestParam("applicationName") String applicationName,
                       @RequestParam("businessId") Long businessId,
                       @RequestParam("businessType") Integer businessType,
                       @RequestBody List<FileInfo> paramList);

    /**
     * 删除文件绑定信息
     *
     * @param businessId 业务id
     */
    @PostMapping(RELIEVE_BINDING_FILE)
    R relieveBindingFile(@RequestParam("businessId") Long businessId);

    /**
     * 获取文件信息
     *
     * @param businessIdList 业务id集合
     */
    @PostMapping(GET_FILE_INFO)
    R<List<FileInfo>> getFileInfo(@RequestBody List<Long> businessIdList);

    @PostMapping(value = UPLOAD_FILE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    R<FileInfo> uploadFile(@RequestPart("file") MultipartFile file);

}
