import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:get/get.dart';

class NotificationController extends GetxController {
  final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
      FlutterLocalNotificationsPlugin();

  // Initializes the local notifications plugin
  Future<void> initNotifications() async {
    const AndroidInitializationSettings android =
        AndroidInitializationSettings('@mipmap/launcher_icon');
    const InitializationSettings initializationSettings =
        InitializationSettings(android: android);
    await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
  }

  // Displays a notification with the given title and message
  void showNotification(String title, String message, String tone) async {
    AndroidNotificationDetails android = AndroidNotificationDetails(
        'your channel id', 'your channel name',
        importance: Importance.max,
        priority: Priority.high,
        showWhen: false,
        sound: RawResourceAndroidNotificationSound(tone));

    NotificationDetails details = NotificationDetails(android: android);
    await _flutterLocalNotificationsPlugin.show(0, title, message, details);
  }
}
