library client_hubs;

import 'package:flutter_modular/flutter_modular.dart';
import 'package:krow_data_connect/krow_data_connect.dart';
import 'package:firebase_auth/firebase_auth.dart' as firebase;
import 'src/data/repositories_impl/hub_repository_impl.dart';
import 'src/domain/repositories/hub_repository_interface.dart';
import 'src/domain/usecases/assign_nfc_tag_usecase.dart';
import 'src/domain/usecases/create_hub_usecase.dart';
import 'src/domain/usecases/delete_hub_usecase.dart';
import 'src/domain/usecases/get_hubs_usecase.dart';
import 'src/presentation/blocs/client_hubs_bloc.dart';
import 'src/presentation/pages/client_hubs_page.dart';

export 'src/presentation/pages/client_hubs_page.dart';

/// A [Module] for the client hubs feature.
class ClientHubsModule extends Module {
  @override
  List<Module> get imports => <Module>[DataConnectModule()];

  @override
  void binds(Injector i) {
    // Repositories
    i.addLazySingleton<HubRepositoryInterface>(
      () => HubRepositoryImpl(
        firebaseAuth: firebase.FirebaseAuth.instance,
        dataConnect: ExampleConnector.instance,
      ),
    );

    // UseCases
    i.addLazySingleton(GetHubsUseCase.new);
    i.addLazySingleton(CreateHubUseCase.new);
    i.addLazySingleton(DeleteHubUseCase.new);
    i.addLazySingleton(AssignNfcTagUseCase.new);

    // BLoCs
    i.add<ClientHubsBloc>(
      () => ClientHubsBloc(
        getHubsUseCase: i.get<GetHubsUseCase>(),
        createHubUseCase: i.get<CreateHubUseCase>(),
        deleteHubUseCase: i.get<DeleteHubUseCase>(),
        assignNfcTagUseCase: i.get<AssignNfcTagUseCase>(),
      ),
    );
  }

  @override
  void routes(RouteManager r) {
    r.child('/', child: (_) => const ClientHubsPage());
  }
}
