import 'services/api_client.dart';
import 'package:get_it/get_it.dart';
import 'blocs/session/session_bloc.dart';
import 'repositories/auth_repository.dart';
import 'repositories/file_repository.dart';
import 'repositories/http_auth_repository.dart';
import 'repositories/http_file_repository.dart';
import 'services/auth_service.dart';
import 'services/file_service.dart';
import 'services/org_api.dart';

final getIt = GetIt.instance;

void configureDependencies(SessionBloc sessionBloc) {
  // Register ApiClient first
  final apiClient = ApiClient(sessionBloc);
  getIt.registerSingleton<ApiClient>(apiClient);

  // Register repositories (HTTP-backed)
  getIt.registerSingleton<AuthRepository>(HttpAuthRepository(apiClient));
  getIt.registerSingleton<FileRepository>(
    HttpFileRepository(FileService(apiClient)),
  );

  // Register services
  getIt.registerSingleton<AuthService>(AuthService(getIt<AuthRepository>()));
  getIt.registerSingleton<FileService>(FileService(getIt<ApiClient>()));
  getIt.registerSingleton<OrgApi>(OrgApi(getIt<ApiClient>()));
}
