import 'package:get/get.dart';
import 'package:nearle/models/summary/deliverystats.dart';
import 'package:nearle/providers/summary/summary.dart';


class SummaryController extends GetxController {
  final SummaryProvider _provider = SummaryProvider();

  // Observables
  var today = 0.obs;
  var week = 0.obs;
  var month = 0.obs;
  var total = 0.obs;
  var cancelled = 0.obs;
  var isLoading = false.obs;

  // Fetch stats and update values
  Future<void> fetchSummaryStats(int userId) async {
    try {
      isLoading.value = true;
      final DeliveryStats? stats = await _provider.fetchSummaryStats(userId);
      if (stats != null) {
        today.value = stats.today;
        week.value = stats.week;
        month.value = stats.month;
        total.value = stats.total;
        cancelled.value = stats.cancelled;
      }
    } catch (e) {
      print('Controller error: $e');
    } finally {
      isLoading.value = false;
    }
  }
}
