import 'package:flutter/widgets.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:krow_core/core.dart';
import 'package:krow_data_connect/krow_data_connect.dart';
import 'data/repositories_impl/client_create_order_repository_impl.dart';
import 'domain/repositories/client_create_order_repository_interface.dart';
import 'domain/usecases/create_one_time_order_usecase.dart';
import 'domain/usecases/create_rapid_order_usecase.dart';
import 'domain/usecases/get_order_types_usecase.dart';
import 'presentation/blocs/client_create_order_bloc.dart';
import 'presentation/blocs/one_time_order_bloc.dart';
import 'presentation/blocs/rapid_order_bloc.dart';
import 'presentation/pages/create_order_page.dart';
import 'presentation/pages/one_time_order_page.dart';
import 'presentation/pages/permanent_order_page.dart';
import 'presentation/pages/rapid_order_page.dart';
import 'presentation/pages/recurring_order_page.dart';

/// Module for the Client Create Order feature.
///
/// This module orchestrates the dependency injection for the create order feature,
/// connecting the domain use cases with their data layer implementations and
/// presentation layer BLoCs.
class ClientCreateOrderModule extends Module {
  @override
  List<Module> get imports => <Module>[DataConnectModule()];

  @override
  void binds(Injector i) {
    // Repositories
    i.addLazySingleton<ClientCreateOrderRepositoryInterface>(ClientCreateOrderRepositoryImpl.new);

    // UseCases
    i.addLazySingleton(GetOrderTypesUseCase.new);
    i.addLazySingleton(CreateOneTimeOrderUseCase.new);
    i.addLazySingleton(CreateRapidOrderUseCase.new);

    // BLoCs
    i.add<ClientCreateOrderBloc>(ClientCreateOrderBloc.new);
    i.add<RapidOrderBloc>(RapidOrderBloc.new);
    i.add<OneTimeOrderBloc>(OneTimeOrderBloc.new);
  }

  @override
  void routes(RouteManager r) {
    r.child(
      '/',
      child: (BuildContext context) => const ClientCreateOrderPage(),
    );
    r.child(
      ClientPaths.childRoute(ClientPaths.createOrder, ClientPaths.createOrderRapid),
      child: (BuildContext context) => const RapidOrderPage(),
    );
    r.child(
      ClientPaths.childRoute(ClientPaths.createOrder, ClientPaths.createOrderOneTime),
      child: (BuildContext context) => const OneTimeOrderPage(),
    );
    r.child(
      ClientPaths.childRoute(ClientPaths.createOrder, ClientPaths.createOrderRecurring),
      child: (BuildContext context) => const RecurringOrderPage(),
    );
    r.child(
      ClientPaths.childRoute(ClientPaths.createOrder, ClientPaths.createOrderPermanent),
      child: (BuildContext context) => const PermanentOrderPage(),
    );
  }
}
