package com.usky.vpp.factory;

import com.usky.common.core.exception.FeignBadRequestException;
import com.usky.vpp.RemoteVppTaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteVppTaskFactory implements FallbackFactory<RemoteVppTaskService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteVppTaskFactory.class);

    @Override
    public RemoteVppTaskService create(Throwable throwable) {
        log.error("VPP 定时任务服务调用失败: {}", throwable.getMessage());
        return new RemoteVppTaskService() {
            @Override
            public void refreshSiteAvgCompletionRate() {
                throw new FeignBadRequestException(500, "定时刷新站点平均完成率异常" + throwable.getMessage());
            }

            @Override
            public void pollUn(Integer tenantId) {
                throw new FeignBadRequestException(500, "定时 UN Poll 异常, tenantId=" + tenantId + throwable.getMessage());
            }

            @Override
            public void registerUn(Integer tenantId) {
                throw new FeignBadRequestException(500, "定时 UN 注册异常, tenantId=" + tenantId + throwable.getMessage());
            }

            @Override
            public void intervalDataReportUn(Integer tenantId) {
                throw new FeignBadRequestException(500, "定时 UN 曲线数据报告异常, tenantId=" + tenantId + throwable.getMessage());
            }
        };
    }
}
