import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class NotificationService {
  static final NotificationService _instance = NotificationService._internal();

  factory NotificationService() => _instance;

  NotificationService._internal();

  FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

  Future<void> initializeNotifications() async {
    const androidSettings = AndroidInitializationSettings(
        '@mipmap/ic_launcher'
    );

    final iosSettings = DarwinInitializationSettings(
      onDidReceiveLocalNotification: (id, title, body, payload) {
        // TODO Navigate to Talk section (This runs when an Notification is tapped)
      },
    );


    final initializationSettings = InitializationSettings(
      android: androidSettings,
      iOS: iosSettings,
    );

    await flutterLocalNotificationsPlugin.initialize(
      initializationSettings,
    );
  }

  Future<void> showNotification({required String title, required String body, required int badgeCount}) async {
    const androidPlatformChannelSpecifics =
    AndroidNotificationDetails(
      'marmobile',
      'Marianum Fulda',
      importance: Importance.defaultImportance,
      priority: Priority.defaultPriority,
      ticker: 'Marianum Fulda',
    );

    const iosPlatformChannelSpecifics = DarwinNotificationDetails();

    const platformChannelSpecifics = NotificationDetails(
      android: androidPlatformChannelSpecifics,
      iOS: iosPlatformChannelSpecifics
    );

    await flutterLocalNotificationsPlugin.show(
      0,
      title,
      body,
      platformChannelSpecifics,
    );
  }
}
