package com.securitycontrol.system.api;

import com.securitycontrol.common.core.constant.SecurityConstants;
import com.securitycontrol.common.core.constant.ServiceNameConstants;
import com.securitycontrol.common.core.domain.Result;
import com.securitycontrol.system.api.domain.SysFile;
import com.securitycontrol.system.api.factory.RemoteFileFallbackFactory;
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.RequestHeader;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件服务
 *
 * @author czc
 */
@FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class)
public interface RemoteFileService {
    /**
     * 上传文件
     *
     * @param file 文件信息
     * @return 结果
     */
    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public Result<SysFile> upload(@RequestPart(value = "file") MultipartFile file);

    /**
     * 获取图片的base64地址
     *
     * @param fileId
     * @param source
     * @return Result<SysFile>
     * @description
     * @author cwchen
     * @date 2024/3/21 15:24
     */
    @PostMapping(value = "/file/getImgBase64")
    public Result<SysFile> getImgBase64(@RequestBody String fileId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);


    /**
     * 获取图片的base64地址
     *
     * @param fileId
     * @param source
     * @return Result<SysFile>
     * @description
     * @author cwchen
     * @date 2024/3/21 15:24
     */
    @PostMapping(value = "/file/getFileBast64")
    public Result<SysFile> getFileBast64(@RequestBody String fileId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 返回字节
     * @param fileId
     * @param source
     * @return
     */
    @PostMapping(value = "/file/getFileByte")
    public Result<byte[]> getFileByte(@RequestBody String fileId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);


    /**
     * 单个文件上传
     *
     * @param file
     * @param source
     * @return AjaxResult
     * @description
     * @author cwchen
     * @date 2024/3/21 17:25
     */
    @PostMapping(value = "/file/singleUploadFile",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public Result singleUploadFile(@RequestPart(value = "file") MultipartFile file,@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 多个文件上传
     *
     * @param files
     * @param source
     * @return AjaxResult
     * @description
     * @author cwchen
     * @date 2024/3/21 17:25
     */
    @PostMapping(value = "/file/mostUploadFile",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public Result mostUploadFile(@RequestPart(value = "files") MultipartFile[] files,@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 删除文件
     * @param fileId
     * @param source
     * @return AjaxResult
     * @description
     * @author cwchen
     * @date 2024/3/21 17:27
     */
    @PostMapping(value = "/file/delFile")
    public Result delFile(@RequestBody String fileId,@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}
