import 'package:cheminova/controller/notification_api_service.dart';
import 'package:cheminova/controller/product_mannual_service.dart';
import 'package:cheminova/models/notification_model.dart';
import 'package:cheminova/notification_service.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../models/product_mannual_model.dart'; // Your model import
// Your service import

class NotificationController extends GetxController {

  var notificationList = <NotificationModel>[].obs;

  // Service to fetch data
  final NotificationApiService notificationApiService = NotificationApiService();

  // Loading state
  var isLoading = false.obs;

  // Method to fetch product manuals from the service
  void fetchNotificationApiService() async {
    try {
      // Set loading to true
      isLoading.value = true;
      SharedPreferences prefs = await SharedPreferences.getInstance();
      String? token = prefs.getString('token');
      var manuals = await notificationApiService.getNotification(token!);

      // If data is returned, update the list
      if (manuals != null) {
        notificationList .value = manuals;
      } else {
        notificationList.value = []; // If no data, set an empty list
      }
    } catch (e) {
      // Handle error here, for example logging or showing an error message
      print("Error fetching product manuals: $e");
    } finally {
      // Set loading to false
      isLoading.value = false;
    }
  }

  @override
  void onInit() {
    // Fetch product manuals when the controller is initialized
    fetchNotificationApiService();
    super.onInit();
  }
}
