package com.vctgo.system.api.factory;

import com.vctgo.common.core.domain.R;
import com.vctgo.system.api.RemoteAreaService;
import com.vctgo.system.api.domain.SysAreaSetting;
import com.vctgo.system.api.domain.dto.SysAreaSettingDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户服务降级处理
 *
 * @author vctgo
 */
@Component
public class RemoteAreaFallbackFactory implements FallbackFactory<RemoteAreaService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteAreaFallbackFactory.class);

    @Override
    public RemoteAreaService create(Throwable throwable) {
        log.error("区域服务调用失败:{}", throwable.getMessage());
        return new RemoteAreaService() {
            @Override
            public R<List<SysAreaSetting>> getSysAreaList() {
                return R.fail("获取全系统区域信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysAreaSetting>> getTenantAreaList(@SpringQueryMap SysAreaSettingDto sysAreaSettingDto) {
                return R.fail("获取当前租户区域信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<String>> getAreaNameByIds(String areaIdStr) {
                return R.fail("获取区域信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysAreaSetting>> getAreaListByIds(List<Long> areaIdList) {
                return R.fail("玩具获取区域信息失败:" + throwable.getMessage());
            }
        };
    }
}
