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

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

part 'unit_construction_admin_event.dart';
part 'unit_construction_admin_state.dart';

class UnitConstructionAdminBloc
    extends Bloc<UnitConstructionAdminEvent, UnitConstructionAdminState> {
  UnitConstructionAdminBloc() : super(UnitConstructionAdminInitial()) {
    List<UnitConstruct> unit = [];
    on<LoadUnitConstruct>((event, emit) async {
      unit = await SQLServices.instance.readAllUnitConstruct();

      emit(UnitConstructLoaded(unit: unit));
    });
    on<AddUnitConstruct>((event, emit) async {
      await SQLServices.instance.createUnitConstruction(
        UnitConstruct(
            id: event.id,
            bldgType: event.bldgType,
            building: event.building,
            unitValue: event.unitValue,
            genCode: event.genCode),
      );
    });
  }
}
