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

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

part 'value_adjustments_event.dart';
part 'value_adjustments_state.dart';

class ValueAdjustmentsBloc
    extends Bloc<ValueAdjustmentsEvent, ValueAdjustmentsState> {
  ValueAdjustmentsBloc() : super(ValueAdjustmentsInitial()) {
    List<ValueAdjustments> valueAdjustments = [];
    on<LoadValueAdjustments>((event, emit) async {
      valueAdjustments = await SQLServices.instance.readAllValueAdjustments();

      emit(ValueAdjustmentsLoaded(valueAdjustments: valueAdjustments));
    });
    on<AddValueAdjustments>((event, emit) async {
      await SQLServices.instance.createValueAdjustments(ValueAdjustments(
        id: event.id,
        landapprDetailsId: event.landapprDetailsId,
        baseMarketval: event.baseMarketval,
        adjustmentFactors: event.adjustmentFactors,
        adjustment: event.adjustment,
        valueAdjustment: event.valueAdjustment,
        marketValue: event.marketValue,
      ));
    });
  }
}
