import 'package:bloc/bloc.dart';
import 'package:easycook_mobile/models/recommedation.dart';
import 'package:easycook_mobile/repositories/dapurku_repository.dart';
import 'package:equatable/equatable.dart';

part 'selected_raw_material_state.dart';

class SelectedRawMaterialCubit extends Cubit<SelectedRawMaterialState> {
  SelectedRawMaterialCubit() : super(SelectedRawMaterialInitial());

  final DapurkuRepositories _repo = DapurkuRepositories();

  Future<void> selectedId(
      {required List<RawMaterial> rawMaterialSelected}) async {
    emit(SelectedRawMaterialLoading());
    try {
      final response = await _repo.addRawMaterialForRecommendation(
          rawMaterialSelected: rawMaterialSelected);
      emit(SelectedRawMaterialSuccess(response.rekomendasiResep));
    } catch (error) {
      emit(SelectedRawMaterialFailure(message: error.toString()));
    }
  }
}
