package com.app.simplitend.apputils;

import static com.app.simplitend.locationupdates.LocationService.LOCATION_NOTIFICATION_CHANNEL_ID;

import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;

import com.onesignal.Continue;
import com.onesignal.OneSignal;
import com.onesignal.debug.LogLevel;
import com.app.simplitend.R;

public class SimpliTendApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        // Verbose Logging set to help debug issues, remove before releasing your app.
        OneSignal.getDebug().setLogLevel(LogLevel.VERBOSE);

        // OneSignal Initialization
        OneSignal.initWithContext(this, getString(R.string.ONE_SIGNAL_APP_ID));

        // requestPermission will show the native Android notification permission prompt.
        OneSignal.getNotifications().requestPermission(true, Continue.with(r -> {
            if (r.isSuccess()) {
                if (r.getData() != null) {
                    // `requestPermission` completed successfully and the user has accepted permission
                } else {
                    // `requestPermission` completed successfully but the user has rejected permission
                }
            }
        }));

        // click listener to notification
        OneSignal.getNotifications().addClickListener(iNotificationClickEvent -> {

        });

        // creating notification channel for location share location updates from patient side
        // using a foreground service
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
            NotificationChannel channel = new NotificationChannel(LOCATION_NOTIFICATION_CHANNEL_ID,
                    "Location updates",
                    NotificationManager.IMPORTANCE_LOW);

            NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notificationManager.createNotificationChannel(channel);
        }
    }

}