import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../../core/network/dio_client.dart';
import '../../data/datasources/terminal_datasource.dart';
import '../../data/repositories/terminal_repository_impl.dart';
import '../../domain/entities/terminal_session.dart';
import '../../domain/repositories/terminal_repository.dart';

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

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

final terminalRepositoryProvider = Provider<TerminalRepository>((ref) {
  final datasource = ref.watch(terminalDatasourceProvider);
  return TerminalRepositoryImpl(datasource);
});

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

/// Provides the list of active terminal sessions.
final activeTerminalSessionsProvider =
    FutureProvider<List<TerminalSession>>((ref) async {
  final repo = ref.watch(terminalRepositoryProvider);
  return repo.getActiveSessions();
});
