import 'package:dio/dio.dart';
import '../../network_api_service/api_service/api_service.dart';
import '../../network_api_service/api_urls/api_urls.dart';
import '../model/help_support_model.dart';

class HelpSupportRepository {
  final ApiService _apiService = ApiService();

  Future<List<HelpSupportModel>> getFaqs() async {
    try {
      final response = await _apiService.get(ApiUrls.faq);

      if (response.statusCode == 200) {
        final List<dynamic> data = response.data;
        return data.map((json) => HelpSupportModel.fromJson(json)).toList();
      } else {
        throw Exception('Failed to load FAQs');
      }
    } on DioException catch (e) {
      if (e.response?.data != null && e.response?.data is Map<String, dynamic>) {
        throw Exception(e.response?.data['message'] ?? 'Failed to load FAQs');
      }
      rethrow;
    } catch (e) {
      throw Exception('$e');
    }
  }
}
