import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../../core/network/dio_client.dart';
import '../../data/datasources/alerts_datasource.dart';
import '../../data/repositories/alerts_repository_impl.dart';
import '../../domain/entities/alert_event.dart';
import '../../domain/repositories/alerts_repository.dart';

// ---------------------------------------------------------------------------
// Dependency providers
// ---------------------------------------------------------------------------

final alertsDatasourceProvider = Provider<AlertsDatasource>((ref) {
  final dio = ref.watch(dioClientProvider);
  return AlertsDatasource(dio);
});

final alertsRepositoryProvider = Provider<AlertsRepository>((ref) {
  final datasource = ref.watch(alertsDatasourceProvider);
  return AlertsRepositoryImpl(datasource);
});

// ---------------------------------------------------------------------------
// Data providers
// ---------------------------------------------------------------------------

/// Provides the full list of alert events.
final alertEventsListProvider =
    FutureProvider<List<AlertEvent>>((ref) async {
  final repo = ref.watch(alertsRepositoryProvider);
  return repo.getAll();
});

/// Provides alert events filtered by severity.
final alertEventsBySeverityProvider =
    FutureProvider.family<List<AlertEvent>, String>((ref, severity) async {
  final repo = ref.watch(alertsRepositoryProvider);
  return repo.getAll(severity: severity);
});
