import 'dart:ui';
import '../../domain/repositories/locale_repository_interface.dart';
import '../datasources/locale_local_data_source.dart';

/// Implementation of [LocaleRepositoryInterface] that coordinates with a local data source.
///
/// This class handles the mapping between domain [Locale] objects and the raw
/// strings handled by the [LocaleLocalDataSource].
class LocaleRepositoryImpl implements LocaleRepositoryInterface {
  final LocaleLocalDataSource _localDataSource;

  /// Creates a [LocaleRepositoryImpl] with the provided [_localDataSource].
  LocaleRepositoryImpl(this._localDataSource);

  @override
  Future<void> saveLocale(Locale locale) {
    return _localDataSource.saveLanguageCode(locale.languageCode);
  }

  @override
  Future<Locale?> getSavedLocale() async {
    final String? languageCode = await _localDataSource.getLanguageCode();
    if (languageCode != null) {
      return Locale(languageCode);
    }
    return null;
  }
}
