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

import '../../../../../sevices/offline/offline_passo/admin/sql_services/sql_services.dart';

part 'land_classification_event.dart';
part 'land_classification_state.dart';

class LandClassificationBloc
    extends Bloc<LandClassificationEvent, LandClassificationState> {
  LandClassificationBloc() : super(LandClassificationInitial()) {
    List<LandClassification> landClassification = [];
    on<LoadLandClassification>((event, emit) async {
      landClassification =
          await SQLServices.instance.readAllLandClassification();

      emit(LandClassificationLoaded(landClassification: landClassification));
    });
    on<AddLandClassification>((event, emit) async {
      await SQLServices.instance.createLandClassification(LandClassification(
          id: event.id,
          classificationCode: event.classificationCode,
          description: event.description));
    });
  }
}
