import 'dart:async';

import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/faq.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';

part 'faq_event.dart';
part 'faq_state.dart';

class FaqBloc extends Bloc<FaqEvent, FaqState> {
  List<Faq>? faqs;
  FaqBloc() : super(FaqInitial()) {
    faqs = Cache().getFaqs();
  }

  @override
  Stream<FaqState> mapEventToState(
    FaqEvent event,
  ) async* {
    try {
      if (event is FaqLoad) {
        yield FaqLoading();
        yield FaqReady();
      } else if (event is FaqClickDetail) {
        yield FaqLoading();
        yield FaqReady();
      }
    } on Exception catch (e) {
      yield FaqError(message: e.toString());
    }
  }
}
