import 'package:dio/dio.dart';
import 'package:english_learning/core/services/dio_client.dart';
import 'package:english_learning/features/home/models/completed_topics_model.dart';

class CompletedTopicsRepository {
  final DioClient _dioClient;

  CompletedTopicsRepository(this._dioClient);

  Future<List<CompletedTopic>> getCompletedTopics(String token) async {
    try {
      final response = await _dioClient.getCompletedTopics(token);
      if (response.statusCode == 200) {
        final List<dynamic> topicsData = response.data['payload'];
        return topicsData.map((data) => CompletedTopic.fromJson(data)).toList();
      } else {
        throw Exception(
            'Failed to load completed topics: ${response.statusMessage}');
      }
    } on DioException catch (e) {
      throw Exception('Network error: ${e.message}');
    } catch (e) {
      throw Exception('Unexpected error: $e');
    }
  }
}
