mirrored_repositories/Cinemapedia-Flutter/lib/presentation/providers




import 'package:cinemapedia/domain/entities/actor.dart';
import 'package:cinemapedia/presentation/providers/actors/actors_repository_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

final actorsByMovieProvider = StateNotifierProvider<ActorsByMovieNotifier, Map<String,List<Actor>>>((ref) {
  final actorsRepository = ref.watch( actorsRepositoryProvider );
  return ActorsByMovieNotifier(getActors: actorsRepository.getActorsByMovie);
});


// ignore: slash_for_doc_comments
/**
 {
  '5014134': <Actor>[],
  '5014135': <Actor>[],
  '5014136': <Actor>[],
 }
 */

typedef GetActorsCallback = Future<List<Actor>> Function(String movieId);

class ActorsByMovieNotifier extends StateNotifier<Map<String,List<Actor>>>{

  final GetActorsCallback getActors;

  ActorsByMovieNotifier({
    required this.getActors
  }): super({});

  Future<void> loadActors( String movieId ) async {
    if( state[movieId] != null ) return;
    // print("Realizando petición HTTP - actors");
    final actors = await getActors(movieId);

    state = {...state, movieId: actors };
  }
  
}