package com.mobify.astro.plugins;

import android.util.Log;
import android.webkit.JavascriptInterface;

import com.mobify.astro.BuildConfig;
import com.mobify.astro.utilities.AstroWebUtilities;

import org.json.JSONException;
import org.json.JSONObject;

import static android.content.ContentValues.TAG;

public class AstroNative {

    @JavascriptInterface
    public String getObject() {
        Boolean isDebug = Boolean.parseBoolean(String.format("%b", BuildConfig.DEBUG));
        Boolean isAstroPreivew = Boolean.parseBoolean(String.format("%b", BuildConfig.ASTRO_PREVIEW));
        JSONObject osInfo = AstroWebUtilities.getOSInfo();
        JSONObject configInfo = new JSONObject();
        JSONObject astroNative = new JSONObject();
        try {
            configInfo.put("DEBUG", isDebug);
            configInfo.put("ASTRO_PREVIEW", isAstroPreivew);
            astroNative.put("Configuration", configInfo);
            astroNative.put("OSInfo", osInfo);
        } catch (JSONException e) {
            Log.e(TAG, e.getMessage(), e);
        }
        return astroNative.toString();
    }

    @JavascriptInterface
    public boolean isPreviewEnabled() {
        return Boolean.parseBoolean(String.format("%b", BuildConfig.ASTRO_PREVIEW));
    }
}
