import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/passo/city.dart';
import 'package:unit2/sevices/passo/municipality.dart';

part 'municipality_event.dart';
part 'municipality_state.dart';

class MunicipalityBloc extends Bloc<MunicipalityEvent, MunicipalityState> {
  MunicipalityBloc() : super(MunicipalityInitial()) {
    on<LoadMunicipality>((event, emit) async {
      emit(MunicipalityLoading());
      try {
        final municipality = await MunicipalityServices.instance.fetch();
        emit(MunicipalityLoaded(municipality));
      } catch (e) {
        emit(MunicipalityErrorState(e.toString()));
      }
    });
  }
}
