package com.xhpc.common.api.factory;

import com.xhpc.common.api.PowerPileService;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.data.down.StartChargingData;
import com.xhpc.common.data.redis.CacheRateModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public class PowerPileFallbackFactory implements FallbackFactory<PowerPileService> {

    private static final Logger logger = LoggerFactory.getLogger(PowerPileFallbackFactory.class);


    @Override
    public PowerPileService create(Throwable cause) {

        logger.error("充电桩服务调用失败:{} //fallback", cause.getMessage());
        return new PowerPileService() {
            @Override
            public R startCharging(StartChargingData startChargingData) {

                return R.fail("启动充电失败:" + cause.getMessage());
            }

            @Override
            public R refreshBalance(StartChargingData balanceRefreshData) {

                return R.fail("刷新余额失败:" + cause.getMessage());
            }

            @Override
            public R stopCharging(String orderNo, String pileNo, String connectorId, String version) {

                return R.fail("停止充电失败:" + cause.getMessage());
            }

            @Override
            public R addPileWhitelist(Long stationId, String version, Set<String> pileNoSet) {

                return R.fail("增加充电桩白名单失败:" + cause.getMessage());
            }

            @Override
            public R deletePileWhitelist(Long stationId, Set<String> pileNoSet) {

                return R.fail("删除充电桩白名单失败:" + cause.getMessage());
            }

            @Override
            public R setStationRateModel(Long stationId, Long rateModelId, CacheRateModel rateModel) {

                return R.fail("设置电站费率模型失败:" + cause.getMessage());
            }

            @Override
            public R configTimeNRateModel(String pileNo) {

                return R.fail("校时校费失败:" + cause.getMessage());
            }

            @Override
            public R pileSoftwareUpgrade(String pileNo) {

                return R.fail("更新桩程序失败:" + cause.getMessage());
            }
        };
    }

}
