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

import com.zd.common.core.domain.R;
import com.zd.common.core.enums.HardwareOperate;
import com.zd.system.api.camera.RemoteCameraService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteCameraFallBackFactory implements FallbackFactory<RemoteCameraService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteCameraFallBackFactory.class);

    @Override
    public RemoteCameraService create(Throwable throwable) {
        log.error("摄像头在线离线调用失败:{}", throwable.getMessage());
        return new RemoteCameraService() {
            @Override
            public R sends(String num, HardwareOperate hardwareOperate) {
                return R.fail("摄像头在线离线调用失败:" + throwable.getMessage());
            }

            @Override
            public R startRecord(String hostname) {
                return R.fail("摄像头开始录像调用失败:" + throwable.getMessage());
            }

            @Override
            public R stopRecord(String hostname) {
                return R.fail("摄像头结束录像调用失败:" + throwable.getMessage());
            }
        };
    }
}
