import 'package:english_learning/core/services/repositories/topic_repository.dart';
import 'package:flutter/foundation.dart';
import 'package:english_learning/features/learning/modules/topics/models/topic_model.dart';

class TopicProvider extends ChangeNotifier {
  final TopicRepository _topicRepository = TopicRepository();
  List<Topic> _topics = [];
  bool _isLoading = false;
  String? _error;

  List<Topic> get topics => _topics;
  bool get isLoading => _isLoading;
  String? get error => _error;

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

    try {
      _topics = await _topicRepository.getTopics(sectionId, token);
    } catch (e) {
      _error = e.toString();
    } finally {
      _isLoading = false;
      notifyListeners();
    }
  }
}
