import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/passo/land_classification.dart';
import 'package:unit2/model/passo/land_subclassification.dart';
import 'package:unit2/sevices/passo/land/land_classification.dart';
import 'package:unit2/sevices/passo/land/land_subclassification.dart';

part 'land_subclassification_event.dart';
part 'land_subclassification_state.dart';

class LandSubClassificationBloc
    extends Bloc<LandSubClassificationEvent, LandSubClassificationState> {
  LandSubClassificationBloc() : super(LandSubClassificationLoading()) {
    on<LoadLandSubClassification>((event, emit) async {
      emit(LandSubClassificationLoading());
      try {
        final classs = await LandSubClassificationService.instance
            .fetch(event.cityCode, event.classCode);
        emit(LandSubClassificationLoaded(classs));
      } catch (e) {
        emit(LandSubClassificationErrorState(e.toString()));
      }
    });
  }
}
