import '../models/notification.dart';
import 'api_client.dart';

class NotificationService {
  final _client = ApiClient.instance;

  Future<List<AppNotification>> getNotifications({bool? unreadOnly}) async {
    final res = await _client.get('/notifications/company', params: {
      if (unreadOnly == true) 'unread': true,
    });
    final list = res.data as List<dynamic>;
    return list
        .map((e) => AppNotification.fromJson(e as Map<String, dynamic>))
        .toList();
  }

  Future<int> getUnreadCount() async {
    final res = await _client.get('/notifications/unread-count');
    return (res.data as Map<String, dynamic>)['unread'] as int? ?? 0;
  }

  Future<void> markRead(String id) async {
    await _client.post('/notifications/company/$id/read');
  }

  Future<void> markAllRead() async {
    await _client.post('/notifications/company/read-all');
  }
}
