import 'package:be_happy/domain/entities/scooter.dart';
import 'package:be_happy/domain/usecase/get_scooter_by_title_usecase.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../event/scooter_code_event.dart';
import '../state/scooter_code_state.dart';

class ScooterCodeBloc extends Bloc<ScooterCodeEvent, ScooterCodeState> {
  final GetScooterByTitleUsecase getScooterByTitleUsecase;

  ScooterCodeBloc({required this.getScooterByTitleUsecase}) : super(const ScooterCodeInitial()) {
    on<ScooterCodeChanged>((event, emit) {
      emit(ScooterCodeInitial(code: event.code));
    });

    on<ScooterCodeSubmitted>((event, emit) async {
      emit(ScooterCodeLoading(code: event.code));

      final result = await getScooterByTitleUsecase(event.code);

      /*result.fold(
        (error) => emit(ScooterCodeFailure(error.message ?? "Ошибка", code: event.code)),
        (scooter) => emit(ScooterCodeSuccess(scooter, code: event.code)),
      );*/
    });
  }
}