package com.xhpc.common.api.factory;

import com.xhpc.common.api.EvcsService;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.domain.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yuyang
 * @date 2023-09-16 19:10
 */
@Component
public class EvcsServiceFallbackFactory implements FallbackFactory<EvcsService> {


    private static final Logger logger = LoggerFactory.getLogger(EvcsServiceFallbackFactory.class);
    /**
     * Returns an instance of the fallback appropriate for the given cause.
     *
     * @param cause cause of an exception.
     * @return fallback
     */
    @Override
    public EvcsService create(Throwable cause) {
        logger.error("Evcs服务调用失败：{}//fallback", cause.getMessage());
        return new EvcsService() {
            @Override
            public R getNotificationConnectorChargeStatus(String serialNumber) {
                return R.fail(500,"Evcs服务--》设备充电中状态变化推送接口失败:" + serialNumber);
            }

            @Override
            public R getCYCNotificationConnectorChargeStatus(Map<String, Object> orderMap) {
                return R.fail(500,"Evcs服务--》川逸充设备充电结束状态变化推送接口失败:" + orderMap);
            }

            @Override
            public R getCYCNotificationStartChargeResult(Map<String, Object> orderMap) {
                return R.fail(500,"Evcs服务--》川逸充启动结果推送接口失败:" + orderMap);
            }

        };
    }
}
