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

part 'user_update_outlet_event.dart';
part 'user_update_outlet_state.dart';
part 'user_update_outlet_bloc.freezed.dart';

class UserUpdateOutletBloc
    extends Bloc<UserUpdateOutletEvent, UserUpdateOutletState> {
  final UserRemoteDatasource _userRemoteDatasource;

  UserUpdateOutletBloc(this._userRemoteDatasource)
      : super(UserUpdateOutletState.initial()) {
    on<_Update>(
      (event, emit) async {
        emit(const _Loading());

        final result = await _userRemoteDatasource.updateOutlet(
          event.outlet,
        );

        result.fold(
          (error) => emit(_Error(error)),
          (success) => emit(_Success()),
        );
      },
    );
  }
}
