import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../data/datasources/pokemon_local_datasource.dart';
import '../../data/datasources/pokemon_remote_datasource.dart';
import '../../data/repositories/pokemon_repository_impl.dart';
import '../../domain/repositories/pokemon_repository.dart';
import 'locale_provider.dart';

/// Point d'injection unique du repository.
/// Se reconstruit automatiquement quand la langue change,
/// ce qui invalide [pokedexProvider] en cascade.
final pokemonRepositoryProvider = Provider<PokemonRepository>((ref) {
  final lang = ref.watch(localeProvider).languageCode;
  final remote = PokemonRemoteDataSource(languageCode: lang);
  final local = kIsWeb ? null : PokemonLocalDataSource(languageCode: lang);
  return PokemonRepositoryImpl(remote: remote, local: local);
});
