package com.mogo.cloud.location.third;

import android.content.Context;
import android.util.Log;

import com.mogo.cloud.location.LocationConfig;
import com.mogo.cloud.location.third.core.LocUploadConfig;
import com.mogo.cloud.location.third.core.LocUploadManager;
import com.mogo.cloud.passport.MoGoAiCloudClient;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;

public class ThirdLocationManager {

    private static final String TAG = "ThirdLocationManager";
    private static volatile ThirdLocationManager mInstance;
    private final MoGoAiCloudClientConfig cloudClientConfig;

    private ThirdLocationManager() {
        cloudClientConfig = MoGoAiCloudClient.getInstance().getAiCloudClientConfig();
    }

    public static ThirdLocationManager getInstance() {
        if (mInstance == null) {
            synchronized (ThirdLocationManager.class) {
                if (mInstance == null) {
                    mInstance = new ThirdLocationManager();
                }
            }
        }
        return mInstance;
    }

    public void init(Context context) {
        LocUploadConfig.instance().
                setAppId(cloudClientConfig.getServiceAppId()).
                setContext(context.getApplicationContext()).
                setLocInterval(1000L);
        if (LocationConfig.isPrintLog) {
            Log.d(TAG, "location sdk - init");
        }
    }

    public void start() {
        LocUploadManager.getInstance().startUpload();
        if (LocationConfig.isPrintLog) {
            Log.d(TAG, "sdk - start");
        }
    }

    public void stop() {
        LocUploadManager.getInstance().stopUpload();
        if (LocationConfig.isPrintLog) {
            Log.d(TAG, "sdk - stop");
        }
    }
}
