// lib/features/home/providers/completed_topics_provider.dart

import 'package:english_learning/core/services/repositories/completed_topics_repository.dart';
import 'package:english_learning/features/home/models/completed_topics_model.dart';
import 'package:flutter/foundation.dart';

class CompletedTopicsProvider with ChangeNotifier {
  final CompletedTopicsRepository _repository;
  List<CompletedTopic> _completedTopics = [];
  bool _isLoading = false;
  String? _error;

  CompletedTopicsProvider(this._repository);

  List<CompletedTopic> get completedTopics => _completedTopics;
  bool get isLoading => _isLoading;
  String? get error => _error;

  Future<void> fetchCompletedTopics(String token) async {
    _isLoading = true;
    _error = null;
    notifyListeners();

    try {
      _completedTopics = await _repository.getCompletedTopics(token);
    } catch (e) {
      _error = e.toString();
      print('Error fetching completed topics: $_error');
    } finally {
      _isLoading = false;
      notifyListeners();
    }
  }
}
