package com.bonus.system.api.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import com.bonus.common.core.domain.R;
import com.bonus.system.api.RemoteFileService;
import com.bonus.system.api.domain.SysFile;

/**
 * 文件服务降级处理
 *
 * @author bonus
 */
@Component
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class);

    @Override
    public RemoteFileService create(Throwable throwable) {
        log.error("文件服务调用失败:{}", throwable.getMessage());
        return new RemoteFileService() {
            @Override
            public R<SysFile> upload(MultipartFile file) {
                return R.fail("上传文件失败:" + throwable.getMessage());
            }
            @Override
            public R<SysFile> getImgBase64(String fileId, String source) {
                return R.fail("文件服务调用失败---获取图片base64地址:" + throwable.getMessage());
            }
            @Override
            public R<SysFile> getFileBast64(String fileId, String source) {
                return R.fail("文件服务调用失败---获取文件Bast64格式:" + throwable.getMessage());
            }

            @Override
            public R<byte[]> getFileByte(String fileId, String source) {
                return R.fail("文件服务调用失败---获取文件流:" + throwable.getMessage());
            }
            @Override
            public R singleUploadFile(MultipartFile file, String source) {
                return R.fail("文件服务调用失败---上传单个文件:" + throwable.getMessage());
            }

            @Override
            public R mostUploadFile(MultipartFile[] files, String source) {
                return R.fail("文件服务调用失败---上传多个文件:" + throwable.getMessage());
            }

            @Override
            public R delFile(String fileId, String source) {
                return R.fail("文件服务调用失败---删除文件:" + throwable.getMessage());
            }

            @Override
            public R uploadFileByBase64(String base64, String source) {
                return R.fail("上传base64文件失败---:" + throwable.getMessage());
            }
        };
    }
}
