import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/passo/general_description.dart';
import 'package:unit2/sevices/passo/building/general_description_services.dart';

part 'general_description_event.dart';
part 'general_description_state.dart';

class GeneralDescriptionBloc
    extends Bloc<GeneralDescriptionEvent, GeneralDescriptionState> {
  GeneralDescriptionBloc() : super(GenDescLoading()) {
    on<LoadGenDesc>((event, emit) async {
      emit(GenDescLoading());
      try {
        final gendesc =
            await GeneralDescriptionServices.instance.fetch(event.id);
        emit(GenDescLoaded(gendesc));
      } catch (e) {
        emit(GenDescErrorState(e.toString()));
      }
    });
  }
}
