package com.cordova.plugin;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.PluginResult;

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

import android.util.Log;

import com.samsung.android.sdk.SsdkUnsupportedException;
import com.samsung.android.sdk.pass.Spass;
import com.samsung.android.sdk.pass.SpassFingerprint;
import com.samsung.android.sdk.pass.SpassInvalidStateException;

public class SamsungPassPlugin extends CordovaPlugin {

    private Spass mSpass;
    private SpassFingerprint mSpassFingerprint;
    private boolean isFeatureEnabled = false;
    private static final String TAG = "SamsungPassPlugin";

    @Override
    public void initialize(final CordovaInterface cordova, CordovaWebView webView) {

        mSpass = new Spass();

        try {
            mSpass.initialize(this.cordova.getActivity().getApplicationContext());
            Log.d(TAG, "Spass was Initialized");
        } catch (SsdkUnsupportedException e) {
            Log.d(TAG, "Spass could not initialize" + e);
        }

        isFeatureEnabled = mSpass.isFeatureEnabled(Spass.DEVICE_FINGERPRINT);
        
        if (isFeatureEnabled) {
            mSpassFingerprint = new SpassFingerprint(this.cordova.getActivity().getApplicationContext());
            Log.d(TAG, "mSpassFingerprint was Initialized");
        } else {
            Log.d(TAG, "Fingerprint Service is not supported in the device.");
        }
    }

    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        
        Log.d(TAG, "Plugin Method Called: " + action);

        if (action.equals("checkSamsungPassSupport")) {
            this.checkSamsungPassSupport(args, callbackContext);
        }
        else {
            return false;
        }

        return true;
    }

    private void checkSamsungPassSupport(JSONArray args, CallbackContext callbackContext) {
        Log.d(TAG, "checkSamsungPassSupport");

        if (isFeatureEnabled) {
            callbackContext.success();
        } else {
            callbackContext.error("Error");
        }
    }

}

@@ -1932,16 +1932,148 @@
 ntext);%0A
+        %7D else if (action.equals(%22checkForRegisteredFingers%22)) %7B%0A            this.checkForRegisteredFingers(args, callbackContext);%0A
         
@@ -2443,10 +2443,388 @@
 %0A    %7D%0A%0A
+    private void checkForRegisteredFingers(JSONArray args, CallbackContext callbackContext) %7B%0A        Log.d(TAG, %22checkForRegisteredFingers%22);%0A%0A        boolean mHasRegisteredFinger = mSpassFingerprint.hasRegisteredFinger();%0A%0A        if (mHasRegisteredFinger) %7B%0A            callbackContext.success();%0A        %7D else %7B%0A            callbackContext.error(%22Error%22);%0A        %7D%0A    %7D%0A%0A
 %7D%0A

add HasRegisteredFinger method