package it.near.sdk.Utils;

import android.app.IntentService;
import android.content.Intent;

import org.json.JSONException;

import it.near.sdk.GlobalConfig;
import it.near.sdk.NearItManager;
import it.near.sdk.R;
import it.near.sdk.Recipes.Models.Recipe;

/**
 * @author cattaneostefano.
 */
public abstract class BaseIntentService extends IntentService {

    public static final int REGION_NOTIFICATION_ID = 1;
    public static final int PUSH_NOTIFICATION_ID = 2;

    /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     *
     * @param name Used to name the worker thread, important only for debugging.
     */
    public BaseIntentService(String name) {
        super(name);
    }

    /**
     * Send a simple notification, and also tracks the recipe as notified.
     * @param intent the intent from the receiver.
     */
    protected void sendSimpleNotification(Intent intent){
        Intent targetIntent = getPackageManager().getLaunchIntentForPackage(this.getPackageName());
        targetIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

        targetIntent.putExtras(intent.getExtras());
        String notif_title = intent.getStringExtra(IntentConstants.NOTIF_TITLE);
        String notifText = intent.getStringExtra(IntentConstants.NOTIF_BODY);
        if (notif_title == null) {
            notif_title = getApplicationInfo().loadLabel(getPackageManager()).toString();
        }
        String recipeId = intent.getStringExtra(IntentConstants.RECIPE_ID);
        try {
            Recipe.sendTracking(getApplicationContext(), recipeId, Recipe.NOTIFIED_STATUS);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        NearNotification.send(this, imgResFromIntent(intent), notif_title, notifText, targetIntent, notificationCodeFromIntent(intent));

    }

    private int imgResFromIntent (Intent intent) {
        if (intent.getAction().equals(NearItManager.PUSH_MESSAGE_ACTION)){
            return R.drawable.ic_send_white_24dp;
        } else if (intent.getAction().equals(NearItManager.GEO_MESSAGE_ACTION)){
            return GlobalConfig.getInstance(this).getNotificationImage();
        }
        return GlobalConfig.getInstance(this).getNotificationImage();
    }

    private int notificationCodeFromIntent(Intent intent) {
        switch (intent.getAction()){
            case NearItManager.PUSH_MESSAGE_ACTION:
                return PUSH_NOTIFICATION_ID;
            case NearItManager.GEO_MESSAGE_ACTION:
                return REGION_NOTIFICATION_ID;
            default:
                return REGION_NOTIFICATION_ID;
        }
    }

}

@@ -717,149 +717,8 @@
  %7D%0A%0A
-    /**%0A     * Send a simple notification, and also tracks the recipe as notified.%0A     * @param intent the intent from the receiver.%0A     */
 %0A   

Revert "java docs for the notification method"