import 'package:flutter_modular/flutter_modular.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'data/datasources/locale_local_data_source.dart';
import 'data/repositories_impl/locale_repository_impl.dart';
import 'domain/repositories/locale_repository_interface.dart';
import 'domain/usecases/get_locale_use_case.dart';
import 'domain/usecases/set_locale_use_case.dart';
import 'bloc/locale_bloc.dart';

/// A [ModularModule] that manages localization dependencies.
///
/// This module registers all necessary data sources, repositories, use cases,
/// and the BLoC required for application-wide localization management.
class LocalizationModule extends Module {
  @override
  void binds(Injector i) {
    // External Dependencies
    i.addInstance<SharedPreferencesAsync>(SharedPreferencesAsync());

    // Data Sources
    i.addSingleton<LocaleLocalDataSource>(
      () => LocaleLocalDataSourceImpl(i.get<SharedPreferencesAsync>()),
    );

    // Repositories
    i.addSingleton<LocaleRepositoryInterface>(
      () => LocaleRepositoryImpl(i.get<LocaleLocalDataSource>()),
    );

    // Use Cases
    i.addSingleton<GetLocaleUseCase>(
      () => GetLocaleUseCase(i.get<LocaleRepositoryInterface>()),
    );
    i.addSingleton<SetLocaleUseCase>(
      () => SetLocaleUseCase(i.get<LocaleRepositoryInterface>()),
    );

    // BLoCs
    i.addSingleton<LocaleBloc>(
      () => LocaleBloc(
        getLocaleUseCase: i.get<GetLocaleUseCase>(),
        setLocaleUseCase: i.get<SetLocaleUseCase>(),
      ),
    );
  }
}
