import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/passo/unit_construct.dart';
import 'package:unit2/sevices/passo/unit_construct_services.dart';

part 'unit_construct_event.dart';
part 'unit_construct_state.dart';

class UnitConstructBloc extends Bloc<UnitConstructEvent, UnitConstructState> {
  UnitConstructBloc() : super(UnitConstructLoading()) {
    on<LoadUnitConstruct>((event, emit) async {
      emit(UnitConstructLoading());
      try {
        final unit = await UnitConstructService.instance.fetch();
        emit(UnitConstructLoaded(unit));
      } catch (e) {
        emit(UnitConstructErrorState(e.toString()));
      }
    });
  }
}
