using Android.App;
using Android.OS;
using GMCabsDriverAssistant.Services;
using GMCabsDriverAssistantSolution.Platforms.Android.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Application = Android.App.Application;

[assembly: Dependency(typeof(NotificationChannelService))]
namespace GMCabsDriverAssistantSolution.Platforms.Android.Services
{
    public class NotificationChannelService : INotificationChannelService
    {
        #region Constants
        public const string TAG = nameof(GMCabsDriverAssistantApplication);
        public static string SILENT_NOTIFICATION_CHANNEL_ID = "GMCabsDriverAssistantSilentNotificationChannel";
        public static string SILENT_NOTIFICATION_CHANNEL_NAME = "GM Cabs Silent Notification Channel";
        public static string SOUND_NOTIFICATION_CHANNEL_ID = "GMCabsDriverAssistantChannel";
        public static string SOUND_NOTIFICATION_CHANNEL_NAME = "GM Cabs Notification Channel";
        public static string SYSTEM_SOUND_NOTIFICATION_CHANNEL_ID = "GMCabsDriverAssistantSystemChannel";
        public static string SYSTEM_SOUND_NOTIFICATION_CHANNEL_NAME = "GM Cabs System Notification Channel";
        #endregion

        public void ManageNotificationChannelService()
        {
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var silentNotificationImportance = NotificationImportance.Low;
                var soundNotificationImportance = NotificationImportance.Max;
                var soundFileName = "newbooking";


                NotificationManager silentNotificationManager = Application.Context.GetSystemService(global::Android.Content.Context.NotificationService) as NotificationManager;
                NotificationManager customNotificationManager = Application.Context.GetSystemService(global::Android.Content.Context.NotificationService) as NotificationManager;
                NotificationManager systemNotificationManager = Application.Context.GetSystemService(global::Android.Content.Context.NotificationService) as NotificationManager;

                /* Delete Notification Channel */
                silentNotificationManager.DeleteNotificationChannel(SILENT_NOTIFICATION_CHANNEL_ID);
                customNotificationManager.DeleteNotificationChannel(SOUND_NOTIFICATION_CHANNEL_ID);
                systemNotificationManager.DeleteNotificationChannel(SYSTEM_SOUND_NOTIFICATION_CHANNEL_ID);

                /*  Silent Notification Channel */

                NotificationChannel silentNotificationchannel = new NotificationChannel(SILENT_NOTIFICATION_CHANNEL_ID, SILENT_NOTIFICATION_CHANNEL_NAME, silentNotificationImportance);
                silentNotificationchannel.EnableVibration(true);
                silentNotificationchannel.LockscreenVisibility = NotificationVisibility.Public;
                silentNotificationManager.CreateNotificationChannel(silentNotificationchannel);

                /*  Custom Sound Notification Channel */

                NotificationChannel soundNotificationChannel = new NotificationChannel(SOUND_NOTIFICATION_CHANNEL_ID, SOUND_NOTIFICATION_CHANNEL_NAME, soundNotificationImportance);
                soundNotificationChannel.EnableVibration(true);
                soundNotificationChannel.LockscreenVisibility = NotificationVisibility.Public;
                soundNotificationChannel.SetSound(global::Android.Net.Uri.Parse("android.resource://au.com.gmcabs.driverassistant/raw/" + soundFileName), null);
                customNotificationManager.CreateNotificationChannel(soundNotificationChannel);

                /*  System Sound Notification Channel */

                NotificationChannel systemSoundNotificationChannel = new NotificationChannel(SYSTEM_SOUND_NOTIFICATION_CHANNEL_ID, SYSTEM_SOUND_NOTIFICATION_CHANNEL_NAME, soundNotificationImportance);
                systemSoundNotificationChannel.EnableVibration(true);
                systemSoundNotificationChannel.LockscreenVisibility = NotificationVisibility.Public;
                systemNotificationManager.CreateNotificationChannel(systemSoundNotificationChannel);
            }

        }
    }
}
