import 'package:flutter_bloc/flutter_bloc.dart';
import '../../model/help_support_model.dart';
import '../../repository/help_support_repository.dart';

part 'help_support_event.dart';
part 'help_support_state.dart';

class HelpSupportBloc extends Bloc<HelpSupportEvent, HelpSupportState> {
  final HelpSupportRepository _helpSupportRepository;

  HelpSupportBloc(this._helpSupportRepository) : super(HelpSupportState.initial()) {
    on<LoadFAQ>(_onLoadFAQ);
  }

  Future<void> _onLoadFAQ(LoadFAQ event, Emitter<HelpSupportState> emit) async {
    emit(state.copyWith(isLoading: true, error: null));
    try {
      final data = await _helpSupportRepository.getFaqs();
      emit(state.copyWith(isLoading: false, faqs: data));
    } catch (e) {
      emit(state.copyWith(isLoading: false, error: e.toString()));
    }
  }
}