library;

import 'package:flutter_modular/flutter_modular.dart';
import 'package:krow_core/core.dart';
import 'package:krow_data_connect/krow_data_connect.dart';
import 'src/data/repositories_impl/auth_repository_impl.dart';
import 'src/domain/repositories/auth_repository_interface.dart';
import 'src/domain/usecases/sign_in_with_email_use_case.dart';
import 'src/domain/usecases/sign_in_with_social_use_case.dart';
import 'src/domain/usecases/sign_out_use_case.dart';
import 'src/domain/usecases/sign_up_with_email_use_case.dart';
import 'src/presentation/blocs/client_auth_bloc.dart';
import 'src/presentation/pages/client_intro_page.dart';
import 'src/presentation/pages/client_get_started_page.dart';
import 'src/presentation/pages/client_sign_in_page.dart';
import 'src/presentation/pages/client_sign_up_page.dart';

export 'src/presentation/pages/client_get_started_page.dart';
export 'src/presentation/pages/client_sign_in_page.dart';
export 'src/presentation/pages/client_sign_up_page.dart';
export 'package:core_localization/core_localization.dart';

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

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

    // UseCases
    i.addLazySingleton(
      () => SignInWithEmailUseCase(i.get<AuthRepositoryInterface>()),
    );
    i.addLazySingleton(
      () => SignUpWithEmailUseCase(i.get<AuthRepositoryInterface>()),
    );
    i.addLazySingleton(
      () => SignInWithSocialUseCase(i.get<AuthRepositoryInterface>()),
    );
    i.addLazySingleton(() => SignOutUseCase(i.get<AuthRepositoryInterface>()));

    // BLoCs
    i.addLazySingleton<ClientAuthBloc>(
      () => ClientAuthBloc(
        signInWithEmail: i.get<SignInWithEmailUseCase>(),
        signUpWithEmail: i.get<SignUpWithEmailUseCase>(),
        signInWithSocial: i.get<SignInWithSocialUseCase>(),
        signOut: i.get<SignOutUseCase>(),
      ),
    );
  }

  @override
  void routes(RouteManager r) {
    r.child(ClientPaths.root, child: (_) => const ClientIntroPage());
    r.child(ClientPaths.getStarted, child: (_) => const ClientGetStartedPage());
    r.child(ClientPaths.signIn, child: (_) => const ClientSignInPage());
    r.child(ClientPaths.signUp, child: (_) => const ClientSignUpPage());
  }
}
