package com.xueyi.file.api.feign.factory;

import com.xueyi.common.core.web.result.R;
import com.xueyi.file.api.domain.SysFile;
import com.xueyi.file.api.feign.RemoteFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 文件服务 降级处理
 *
 * @author xueyi
 */
@Slf4j
@Component
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService> {

    @Override
    public RemoteFileService create(Throwable throwable) {
        log.error("文件服务调用失败:{}", throwable.getMessage());
        return new RemoteFileService() {
            @Override
            public R<SysFile> upload(MultipartFile file, String extension, String uuid) {
                return R.fail("上传文件失败:" + throwable.getMessage());
            }

            @Override
            public R<SysFile> uploadNoAsync(MultipartFile file, String extension, String fileUuid) {
                return null;
            }

            @Override
            public R<SysFile> uploadFace(MultipartFile file) {
                return R.fail("上传文件失败:" + throwable.getMessage() );
            }

            @Override
            public R<SysFile> uploadTemp(MultipartFile file) {
                return null;
            }

            @Override
            public R<List<SysFile>> uploadPdf(MultipartFile file, String uuid) {
                return R.fail("上传文件失败:" + throwable.getMessage() );
            }

            @Override
            public R<Boolean> delete(String url) {
                return R.fail("删除文件失败:" + throwable.getMessage());
            }
        };
    }
}