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

import com.alibaba.fastjson2.JSONObject;
import com.xueyi.common.core.web.result.R;
import com.xueyi.tenant.api.tenant.domain.dto.TeTenantDto;
import com.xueyi.tenant.api.tenant.feign.RemoteTenantService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 租户服务降级处理
 *
 * @author xueyi
 */
@Slf4j
@Component
public class RemoteTenantFallbackFactory implements FallbackFactory<RemoteTenantService> {

    @Override
    public RemoteTenantService create(Throwable throwable) {
        log.error("租户服务调用失败:{}", throwable.getMessage());
        return new RemoteTenantService() {
            @Override
            public R<Boolean> registerTenantInfo(JSONObject register, String source)
            {
                return R.fail("注册租户失败:" + throwable.getMessage());
            }

            @Override
            public R<List<TeTenantDto>> tenantList() {
                return null;
            }
        };
    }
}