import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';

import '../../../../../model/passo/type_of_road.dart';
import '../../../../../sevices/offline/offline_passo/admin/sql_services/sql_services.dart';

part 'type_of_road_event.dart';
part 'type_of_road_state.dart';

class TypeOfRoadBloc extends Bloc<TypeOfRoadEvent, TypeOfRoadState> {
  TypeOfRoadBloc() : super(TypeOfRoadInitial()) {
    List<TypeOfRoad> typeOfRoad = [];
    on<LoadTypeOfRoad>((event, emit) async {
      typeOfRoad = await SQLServices.instance.readAllTypeOfRoad();

      emit(TypeOfRoadLoaded(typeOfRoad: typeOfRoad));
    });
    on<AddTypeOfRoad>((event, emit) async {
      await SQLServices.instance.createTypeOfRoad(TypeOfRoad(
        id: event.id,
        roadType: event.roadType,
        deduction: event.deduction,
      ));
    });
  }
}
