import 'package:bloc/bloc.dart';

import '../../../Api_Helper/base_manager.dart';
import '../../../Globalconst.dart';
import '../domain/Repository/otp_api.dart';
import 'otp_event.dart';
import 'otp_state.dart';

class OTPBloc extends Bloc<OTPEvent, OTPState> {
  OTPBloc() : super(OTPInitial()) {
    on<RequestOTP>(requestOTPCall);
    // on<VerifyOTP>(VerifyOTPCall);
  }
  Future<void> requestOTPCall(RequestOTP event, Emitter<OTPState> emit) async {
    emit(OTPLoading());
    final otprequestdata = event.OTPRequestData;

    try {
      ResponseData response = await OTPAPI().requestOTP(otprequestdata);
      if (response.status == ResponseStatus.SUCCESS) {
        emit(OTPLoaded());
      } else {
        emit(OTPFailed(response.message.toString()));
      }
    } catch (e) {
      emit(OTPError(Globalconst.languageSelected == "en"
          ? "تبا شيء ما حدث بشكل خاطئ"
          : ""));
    }
  }
}
