import 'package:cheminova/services/api_service.dart';
import 'package:get/get.dart';
import '../models/NotificationListResponse.dart';

import '../utils/api_urls.dart';

class NotificationController extends GetxController {
  final ApiService _apiClient = ApiService();
  RxList<Notifications> notificationsList = <Notifications>[].obs;
  RxBool isLoading = false.obs;

  @override
  void onInit() {
    super.onInit();
    getNotification();
  }

  Future<void> getNotification() async {
    isLoading.value = true;
    try {
      final response = await _apiClient.get(ApiUrls.getNotificationUrl);
      isLoading.value = false;
      if (response.statusCode == 200) {
        final data = NotificationListResponse.fromJson(response.data);
        notificationsList.value = data.notifications ?? [];
      }
    } catch (e) {
      isLoading.value = false;
      Get.snackbar('Error', 'Failed to fetch notifications');
    }
  }
}