import 'package:bloc/bloc.dart';
import 'package:easycook_mobile/models/recipe_detail.dart';
import 'package:equatable/equatable.dart';
import 'package:easycook_mobile/repositories/recipe_detail_repository.dart';
import 'package:flutter/foundation.dart';

part 'recipe_detail_state.dart';

class RecipeDetailCubit extends Cubit<RecipeDetailState> {
  RecipeDetailCubit() : super(RecipeDetailInitial());

  final RecipeDetailRepositories _recipeDetail = RecipeDetailRepositories();

  Future<void> recipeDetail({required int id}) async {
    emit(RecipeDetailLoading());
    try {
      final response = await _recipeDetail.getRecipeDetail(id);
      emit(RecipeDetailSucces(recipeDetail: response));
    } catch (error) {
      emit(RecipeDetailFailure(message: error.toString()));
    }
  }
}
