package com.bonus.system.api.factory;

import com.bonus.common.core.domain.R;
import com.bonus.system.api.RemoteLogService;
import com.bonus.system.api.RemoteSourceService;
import com.bonus.system.api.RemoteUserService;
import com.bonus.system.api.domain.SysFileSource;
import com.bonus.system.api.domain.SysUser;
import com.bonus.system.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 文件资源降级处理
 * 
 * @author bonus
 */
@Component
public class RemoteSourceFallbackFactory implements FallbackFactory<RemoteSourceService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteSourceFallbackFactory.class);


    @Override
    public RemoteSourceService create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new RemoteSourceService() {
            @Override
            public R<Boolean> addFileSource(SysFileSource sysFileSource, String source) throws Exception {
                return R.fail("添加文件资源失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> delSourceFile(SysFileSource sysFileSource, String source) throws Exception {
                return R.fail("删除文件资源失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysFileSource>> getSourceFileList(String sourceId, String source) throws Exception {
                return R.fail("查询文件资源失败:" + throwable.getMessage());
            }
        };
    }
}
