package com.mogo.cloud.location;

import android.content.Context;

import com.mogo.cloud.location.internal.InternalLocationManager;
import com.mogo.cloud.location.third.ThirdLocationManager;
import com.mogo.cloud.passport.MoGoAiCloudClient;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;

public class LocationManager implements IMogoLocationInfoService {

    private static volatile LocationManager mInstance;
    private final MoGoAiCloudClientConfig cloudClientConfig;

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

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

    @Override
    public void init(Context context) {
        setDebugMode(cloudClientConfig.isShowDebugLog());
        if (cloudClientConfig.isThirdLogin()) {
            ThirdLocationManager.getInstance().init(context);
        } else {
            InternalLocationManager.getInstance().init(context);
        }
    }

    private void setDebugMode(Boolean debugMode) {
        LocationConfig.isPrintLog = debugMode;
    }

    @Override
    public void start() {
        if (cloudClientConfig.isThirdLogin()) {
            ThirdLocationManager.getInstance().start();
        } else {
            InternalLocationManager.getInstance().start();
        }
    }

    @Override
    public void stop() {
        if (cloudClientConfig.isThirdLogin()) {
            ThirdLocationManager.getInstance().stop();
        } else {
            InternalLocationManager.getInstance().stop();
        }
    }
}
