import 'package:cheminova/models/notification_model.dart';
import 'package:cheminova/utils/api_urls.dart';

import '../utils/common_api_service.dart';

class NotificationApiService {
  Future<List<NotificationModel>?> getNotification(String token) async {
    try {
      String url =ApiUrls.getNotificationUrl; // Base URL to fetch product manuals

      final response = await commonApiService<List<NotificationModel>>(
        method: "GET",
        url: url,
        additionalHeaders: {  // Pass the token here
          'Authorization': 'Bearer $token',
        },
        fromJson: (json) {
          if (json['notifications'] != null) {
            // Map the list of product manuals from the response
            final List<NotificationModel> notification = (json['notifications'] as List)
                .map((manualJson) => NotificationModel.fromJson(manualJson as Map<String, dynamic>))
                .toList();
            return notification;
          } else {
            return [];
          }
        },
      );
      return response;
    } catch (e) {

      print(e.toString());
      return null;
    }
  }
}
