package com.microservices.system.api.factory;

import com.alibaba.fastjson2.JSONObject;
import com.microservices.system.api.RemoteGatewayService;
import feign.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

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

    @Override
    public RemoteGatewayService create(Throwable throwable) {
        log.error("网关服务调用失败:{}", throwable.getMessage());
        return new RemoteGatewayService() {

            @Override
            public Response loginSentinel(String password, String username) {
                return null;
            }

            @Override
            public Response loginNacos(Map<String, ?> formParams) {
                return null;
            }

            @Override
            public Response loginPortainer(JSONObject loginBody) {
                System.out.println(throwable.getMessage());
                return null;
            }
        };
    }
}
