package com.zd.system.api.netty.factory;

import com.zd.common.core.domain.R;
import com.zd.system.api.laboratory.domain.RemoteLabHardware;
import com.zd.system.api.netty.RemoteNettyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteNettyFallbackFactory implements FallbackFactory<RemoteNettyService> {

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

    @Override
    public RemoteNettyService create(Throwable throwable) {
        log.error("netty服务调用失败:{}", throwable.getMessage());
        return new RemoteNettyService() {
            @Override
            public R<Boolean> disconnect(RemoteLabHardware hardware) {
                return  R.fail("停止扫描失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> startMonitorChannels(RemoteLabHardware hardware) {
                return  R.fail("启动扫描失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> alarm(RemoteLabHardware hardware) {
                return  R.fail("开启警报失败:" + throwable.getMessage());
            }
        };
    }
}
