import 'package:flutter_modular/flutter_modular.dart';
import 'package:krow_data_connect/krow_data_connect.dart';
import 'src/data/repositories_impl/home_repository_impl.dart';
import 'src/domain/repositories/home_repository_interface.dart';
import 'src/domain/usecases/get_dashboard_data_usecase.dart';
import 'src/domain/usecases/get_recent_reorders_usecase.dart';
import 'src/domain/usecases/get_user_session_data_usecase.dart';
import 'src/presentation/blocs/client_home_bloc.dart';
import 'src/presentation/pages/client_home_page.dart';

export 'src/presentation/pages/client_home_page.dart';
export 'src/presentation/navigation/client_home_navigator.dart';

/// A [Module] for the client home feature.
///
/// This module configures the dependencies for the client home feature,
/// including repositories, use cases, and BLoCs.
class ClientHomeModule extends Module {
  @override
  List<Module> get imports => <Module>[DataConnectModule()];

  @override
  void binds(Injector i) {
    // Repositories
    i.addLazySingleton<HomeRepositoryInterface>(
      () => HomeRepositoryImpl(
        i.get<HomeRepositoryMock>(),
        ExampleConnector.instance,
      ),
    );

    // UseCases
    i.addLazySingleton(GetDashboardDataUseCase.new);
    i.addLazySingleton(GetRecentReordersUseCase.new);
    i.addLazySingleton(GetUserSessionDataUseCase.new);

    // BLoCs
    i.add<ClientHomeBloc>(
      () => ClientHomeBloc(
        getDashboardDataUseCase: i.get<GetDashboardDataUseCase>(),
        getRecentReordersUseCase: i.get<GetRecentReordersUseCase>(),
        getUserSessionDataUseCase: i.get<GetUserSessionDataUseCase>(),
      ),
    );
  }

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