import '../../models/notification_model.dart';
import '../interfaces/notification_service.dart';
import 'api_client.dart';

class NotificationApiService implements NotificationService {
  final ApiClient _client;

  NotificationApiService(this._client);

  @override
  Future<NotificationList> getNotifications() async {
    final List<dynamic> data = await _client.get('/admin/notifications');
    return data
        .map((json) => NotificationModel.fromJson(json as Map<String, dynamic>))
        .toList();
  }

  @override
  Future<void> sendPublicNotification(String title, String description) async {
    final encodedTitle = Uri.encodeQueryComponent(title);
    final encodedDesc = Uri.encodeQueryComponent(description);
    await _client.post(
      '/notifications/public?title=$encodedTitle&description=$encodedDesc',
      {},
    );
  }
}
