using Android.App;
using Android.Content;
using Android.OS;
using AndroidX.Core.App;
using GMCabsDriverAssistantSolution.Platforms.Android.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

[assembly: Dependency(typeof(NotificationHelper))]
namespace GMCabsDriverAssistantSolution.Platforms.Android.Helpers
{
    internal class NotificationHelper : INotification
    {
        private static string foregroundChannelId = "9001";
        private static Context context = global::Android.App.Application.Context;

        public Notification ReturnNotif()
        {
            var intent = new Intent(context, typeof(MainActivity));
            intent.AddFlags(ActivityFlags.SingleTop);
            intent.PutExtra("Title", "Message");

            var pendingIntentFlags = (Build.VERSION.SdkInt >= BuildVersionCodes.S)
              ? PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable
              : PendingIntentFlags.UpdateCurrent;
            var pendingActivityIntent = PendingIntent.GetActivity(context, 0, intent, pendingIntentFlags);
            var pendingIntent = PendingIntent.GetBroadcast(context, 0, intent, pendingIntentFlags);

            var notifBuilder = new NotificationCompat.Builder(context, foregroundChannelId)
             .SetContentTitle("Location")
             .SetContentText("Update location")
             .SetOngoing(true)
             .SetContentIntent(pendingIntent);


            if (global::Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                NotificationChannel notificationChannel = new NotificationChannel(foregroundChannelId, "Title", NotificationImportance.High);
                notificationChannel.Importance = NotificationImportance.High;
                notificationChannel.EnableLights(true);
                notificationChannel.EnableVibration(true);
                notificationChannel.SetShowBadge(true);
                notificationChannel.SetVibrationPattern(new long[] { 100, 200, 300 });

                var notifManager = context.GetSystemService(Context.NotificationService) as NotificationManager;
                if (notifManager != null)
                {
                    notifBuilder.SetChannelId(foregroundChannelId);
                    notifManager.CreateNotificationChannel(notificationChannel);
                }
            }

            return notifBuilder.Build();
        }
    }
}