import 'package:english_learning/core/services/dio_client.dart';
import 'package:english_learning/features/learning/modules/model/section_model.dart';

class SectionRepository {
  final DioClient _dioClient = DioClient();

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