import 'package:feature_inventory/feature_inventory.dart';
import 'package:feature_orders/feature_orders.dart';
import 'package:feature_wordpress/feature_wordpress.dart';

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

/// Use case: fetches data from all three repositories and returns an
/// aggregated [DashboardSummary].
///
/// This lives in the app layer (not in a feature package) because it
/// crosses feature boundaries. Mirrors `kell_web`'s equivalent use case.
class GetDashboardSummary {
  final InventoryRepository inventoryRepository;
  final ProductPublishingRepository productPublishingRepository;
  final OrdersRepository ordersRepository;

  GetDashboardSummary({
    required this.inventoryRepository,
    required this.productPublishingRepository,
    required this.ordersRepository,
  });

  Future<DashboardSummary> call() async {
    final results = await Future.wait([
      inventoryRepository.getInventoryItems(),
      productPublishingRepository.getProductDrafts(),
      ordersRepository.getOrders(),
    ]);

    return DashboardSummary.fromData(
      inventoryItems: results[0] as List<InventoryItem>,
      productDrafts: results[1] as List<ProductDraft>,
      orders: results[2] as List<Order>,
    );
  }
}
