package com.mogo.cloud.trafficlive.api;

import android.util.Log;
import android.view.SurfaceView;
import android.view.TextureView;

import com.mogo.cloud.trafficlive.core.TrafficLiveCurrentManager;

import static com.mogo.cloud.trafficlive.constant.TrafficLiveConstant.TAG;

public class MoGoAiCloudTrafficLive {

    /**
     * 查看前方车辆直播
     *
     * @param lat         纬度
     * @param lon         经度
     * @param bearing     方向角
     * @param surfaceView 直播界面
     * @param callBack    {@link ITrafficCarLiveCallBack}直播回调
     */
    public static void viewFrontVehicleLive(double lat, double lon, int bearing, SurfaceView surfaceView, ITrafficCarLiveCallBack callBack) {
        try {
            TrafficLiveCurrentManager.getInstance().viewFrontVehicleLive(lat, lon, bearing, surfaceView, callBack);
        } catch (Exception e) {
            Log.e(TAG, " viewFrontVehicleLive error : " + e);
            callBack.onError(e != null ? e.getMessage() : "check input param");
            e.printStackTrace();
        }
    }

    /**
     * 查看指定SN车辆直播
     *
     * @param liveSn      直播车辆SN
     * @param surfaceView 直播界面
     * @param callBack    {@link ITrafficCarLiveCallBack}直播回调
     */
    public static void viewDesignativeVehicleLive(String liveSn, SurfaceView surfaceView, ITrafficCarLiveCallBack callBack) {
        try {
            TrafficLiveCurrentManager.getInstance().viewDesignativeVehicleLive(liveSn, surfaceView, callBack);
        } catch (Exception e) {
            Log.e(TAG, " viewDesignativeVehicleLive error : " + e);
            callBack.onError(e != null ? e.getMessage() : "check input param");
            e.printStackTrace();
        }
    }

    public static void viewDesignativeVehicleLive(String liveSn, TextureView textureView, ITrafficCarLiveCallBack callBack) {
        try {
            TrafficLiveCurrentManager.getInstance().viewDesignativeVehicleLive(liveSn, textureView, callBack);
        } catch (Exception e) {
            Log.e(TAG, " viewDesignativeVehicleLive error : " + e);
            callBack.onError(e != null ? e.getMessage() : "check input param");
            e.printStackTrace();
        }
    }

    /**
     * 查看前方路口直播
     *
     * @param lat      纬度
     * @param lon      经度
     * @param bearing  方向角
     * @param callBack {@link ITrafficIntersectionLiveCallBack}直播回调
     */
    public static void viewFrontIntersectionLive(double lat, double lon, int bearing, ITrafficIntersectionLiveCallBack callBack) {
        try {
            TrafficLiveCurrentManager.getInstance().viewFrontIntersectionLive(lat, lon, bearing, callBack);
        } catch (Exception e) {
            Log.e(TAG, " viewFrontIntersectionLive error : " + e);
            callBack.onError(e != null ? e.getMessage() : "check input param");
            e.printStackTrace();
        }
    }

    /**
     * 查看指定路口摄像头直播
     *
     * @param cameraId 设备id
     * @param callBack {@link ITrafficIntersectionLiveCallBack}直播回调
     */
    public static void viewDesignativeIntersectionLive(String cameraId, ITrafficIntersectionLiveCallBack callBack) {
        try {
            TrafficLiveCurrentManager.getInstance().viewDesignativeIntersectionLive(cameraId, callBack);
        } catch (Exception e) {
            Log.e(TAG, " viewDesignativeIntersectionLive error : " + e);
            callBack.onError(e != null ? e.getMessage() : "check input param");
            e.printStackTrace();
        }
    }

    /**
     * 停止观看车辆直播
     *
     * @param liveSn 车辆SN
     */
    public static void stopCarLive(String liveSn) {
        TrafficLiveCurrentManager.getInstance().stopCarLive(liveSn);
    }

    /**
     * 车辆是否在直播中
     *
     * @return 直播状态
     */
    public static boolean isCarOnLive() {
        return TrafficLiveCurrentManager.getInstance().isCarOnLive();
    }
}
