import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:krow_data_connect/krow_data_connect.dart';

import 'data/repositories/personal_info_repository_impl.dart';
import 'domain/repositories/personal_info_repository_interface.dart';
import 'domain/usecases/get_personal_info_usecase.dart';
import 'domain/usecases/update_personal_info_usecase.dart';
import 'presentation/blocs/personal_info_bloc.dart';
import 'presentation/pages/personal_info_page.dart';

/// The entry module for the Staff Profile Info feature.
///
/// This module provides routing and dependency injection for
/// personal information functionality following Clean Architecture.
///
/// The module:
/// - Registers repository implementations
/// - Registers use cases that contain business logic
/// - Registers BLoC for state management
/// - Defines routes for navigation
class StaffProfileInfoModule extends Module {
  @override
  void binds(Injector i) {
    // Repository
    i.addLazySingleton<PersonalInfoRepositoryInterface>(
      () => PersonalInfoRepositoryImpl(
        dataConnect: ExampleConnector.instance,
        firebaseAuth: FirebaseAuth.instance,
      ),
    );

    // Use Cases - delegate business logic to repository
    i.addLazySingleton<GetPersonalInfoUseCase>(
      () => GetPersonalInfoUseCase(i.get<PersonalInfoRepositoryInterface>()),
    );
    i.addLazySingleton<UpdatePersonalInfoUseCase>(
      () => UpdatePersonalInfoUseCase(i.get<PersonalInfoRepositoryInterface>()),
    );

    // BLoC - manages presentation state
    i.addLazySingleton<PersonalInfoBloc>(
      () => PersonalInfoBloc(
        getPersonalInfoUseCase: i.get<GetPersonalInfoUseCase>(),
        updatePersonalInfoUseCase: i.get<UpdatePersonalInfoUseCase>(),
      ),
    );
  }

  @override
  void routes(RouteManager r) {
    r.child(
      '/personal-info',
      child: (BuildContext context) => const PersonalInfoPage(),
    );
    // Alias with trailing slash to be tolerant of external deep links
    r.child(
      '/personal-info/',
      child: (BuildContext context) => const PersonalInfoPage(),
    );
  }
}
