import 'package:flutter/foundation.dart';

import '../domain/dashboard_summary.dart';
import 'get_dashboard_summary.dart';

/// Controller that manages the dashboard summary state.
///
/// Follows the same [ChangeNotifier] pattern used by other feature
/// controllers. Mirrors `kell_web`'s equivalent controller.
class DashboardController extends ChangeNotifier {
  final GetDashboardSummary _getDashboardSummary;

  DashboardController(this._getDashboardSummary);

  bool isLoading = false;
  DashboardSummary summary = DashboardSummary.empty;
  Object? error;

  /// Loads the aggregated dashboard summary from all repositories.
  Future<void> load() async {
    isLoading = true;
    error = null;
    notifyListeners();

    try {
      summary = await _getDashboardSummary();
    } catch (e) {
      error = e;
    } finally {
      isLoading = false;
      notifyListeners();
    }
  }
}
