import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/passo/structural_materials_ii.dart';
import 'package:unit2/model/passo/structureMaterial.dart';
import 'package:unit2/sevices/passo/building/structural_material_services.dart';

part 'structural_material_event.dart';
part 'structural_material_state.dart';

class StructuralMaterialBloc
    extends Bloc<StructuralMaterialEvent, StructuralMaterialState> {
  StructuralMaterialBloc() : super(StructuralMaterialInitial()) {
    on<LoadStructuralMaterial>((event, emit) async {
      emit(StructuralMaterialsLoading());
      try {
        final structure = await StrucMaterialServices.instance.fetch(event.id);
        emit(StructuralMaterialsLoaded(structure));
      } catch (e) {
        emit(StructuralMaterialsErrorState(e.toString()));
      }
    });
  }
}
