// notification_service.dart
import 'dart:convert';
import 'package:tm_app/core/utils/result.dart';
import 'package:tm_app/data/services/api/notification_api.dart';
import 'package:tm_app/data/services/model/notification__response/notification_response_model.dart';
import '../../core/network/network_manager.dart';

class NotificationsService {
  NotificationsService({required NetworkManager networkManager})
    : _networkManager = networkManager;
  final NetworkManager _networkManager;

  Future<Result<NotificationResponseModel>> getNotifications({
    required int limit,
    required int offset,
  }) async {
    final result = await _networkManager.makeRequest(
      NotificationApi.getNotifications(limit: limit, offset: offset),
      method: 'GET',
      (json) => NotificationResponseModel.fromJson(json),
    );
    return result;
  }

  Future<Result<Map<String, dynamic>>> markAllAsRead() async {
    final result = await _networkManager.makeRequest(
      NotificationApi.markAllAsRead,
      method: 'GET',
      (json) => json,
    );
    return result;
  }

  Future<Result<NotificationResponseModel>> markAsRead({
    required String notificationId,
  }) async {
    final data = jsonEncode({'notification_id': notificationId});
    final result = await _networkManager.makeRequest(
      NotificationApi.markAsRead,
      method: 'POST',
      (json) => NotificationResponseModel.fromJson(json),
      data: data,
    );  
    return result;
  }

  Future<Result<NotificationResponseModel>> getUnreadNotifications({
    required int limit,
    required int offset,
  }) async {
    final result = await _networkManager.makeRequest(
      NotificationApi.getUnreadNotifications(limit: limit, offset: offset),
      method: 'GET',
      (json) => NotificationResponseModel.fromJson(json),
    );
    return result;
  }

  Future<Result<NotificationResponseModel>> getImportantNotifications({
    required int limit,
    required int offset,
  }) async {
    final result = await _networkManager.makeRequest(
      NotificationApi.getImportantNotifications(limit: limit, offset: offset),
      method: 'GET',
      (json) => NotificationResponseModel.fromJson(json),
    );
    return result;
  }
}
