import 'dart:developer';


import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:krow/core/application/di/injectable.dart';
import 'package:krow/core/data/enums/state_status.dart';
import 'package:krow/features/profile/faq/domain/entities/faq_entry.dart';
import 'package:krow/features/profile/faq/domain/faq_repository.dart';


part 'faq_event.dart';

part 'faq_state.dart';

class FaqBloc extends Bloc<FaqEvent, FaqState> {
  FaqBloc() : super(const FaqState()) {
    on<InitializeFAQ>((event, emit) async {
      emit(state.copyWith(status: StateStatus.loading));

      List<FaqEntry> entries = [];
      try {
        entries = await getIt<FaqRepository>().getFaqData();
      } catch (except) {
        log('Error in FaqBloc, on InitializeFAQ', error: except);
        emit(state.copyWith(status: StateStatus.error));
      }

      emit(
        state.copyWith(
          status: StateStatus.idle,
          entries: entries,
        ),
      );
    });
  }
}
