import 'package:english_learning/core/services/dio_client.dart';
import 'package:english_learning/features/learning/modules/topics/models/topic_model.dart';

class TopicRepository {
  final DioClient _dioClient = DioClient();

  Future<List<Topic>> getTopics(String sectionId, String token) async {
    try {
      final response = await _dioClient.getTopics(sectionId, token);
      if (response.statusCode == 200) {
        final Map<String, dynamic> responseData = response.data;
        final List<dynamic> data = responseData['payload'];
        return data.map((json) => Topic.fromJson(json)).toList();
      } else {
        throw Exception('Failed to load topics: ${response.statusCode}');
      }
    } catch (e) {
      print('Error in TopicRepository: $e');
      rethrow;
    }
  }
}
