import 'dart:ui';

import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/table_remote_datasource.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'change_position_table_event.dart';
part 'change_position_table_state.dart';
part 'change_position_table_bloc.freezed.dart';

class ChangePositionTableBloc
    extends Bloc<ChangePositionTableEvent, ChangePositionTableState> {
  final TableRemoteDataSource _tableRemoteDataSource;
  ChangePositionTableBloc(this._tableRemoteDataSource)
      : super(ChangePositionTableState.initial()) {
    on<_ChangePositionTable>((event, emit) async {
      emit(_Loading());
      final result = await _tableRemoteDataSource.updatePosition(
        tableId: event.tableId,
        position: event.position,
      );
      result.fold(
        (l) => emit(_Error(l)),
        (r) => emit(_Success('Generate Success')),
      );
      emit(_Success('Generate Success'));
    });
  }
}
