/// Shared composition abstractions for app service containers.
///
/// Provides [KcAppServices] as an abstract base and [KcServiceFactory] as
/// the generic factory pattern used by [KcBootstrap] to construct services.
library;

import 'kc_app_config.dart';

/// Abstract base class for application service containers.
///
/// Each app target (`kell_web`, `kell_mobile`) creates a concrete subclass
/// that holds the specific repository and service implementations needed by
/// that target. The base class defines the factory contract that
/// [KcBootstrap] uses to construct services from a [KcAppConfig].
///
/// ## Pattern
///
/// ```dart
/// class WebAppServices extends KcAppServices {
///   final InventoryRepository inventoryRepository;
///   final ProductPublishingRepository productPublishingRepository;
///   // ...
///
///   const WebAppServices({
///     required this.inventoryRepository,
///     required this.productPublishingRepository,
///   });
/// }
/// ```
///
/// ## Why abstract?
///
/// Concrete service containers reference feature-package repository types
/// directly. Moving those references into `core` would create circular
/// dependencies (`core` → feature → `core`). By keeping the base abstract,
/// `core` owns the composition *contract* without knowing concrete types.
abstract class KcAppServices {
  const KcAppServices();
}

/// A factory that constructs the appropriate [KcAppServices] subclass
/// from a [KcAppConfig].
///
/// Each app target provides two factories — one for fake mode and one for
/// the real backend — via [KcServiceFactory].
///
/// ```dart
/// final factory = KcServiceFactory<WebAppServices>(
///   createFake: () => WebAppServices.fake(),
///   createWordPress: (config) => WebAppServices.wordpress(
///     siteUrl: config.wcSiteUrl,
///     consumerKey: config.wcConsumerKey,
///     consumerSecret: config.wcConsumerSecret,
///   ),
/// );
/// ```
class KcServiceFactory<T extends KcAppServices> {
  /// Creates services backed by fake, in-memory repositories.
  final T Function() createFake;

  /// Creates services backed by the real WordPress/WooCommerce backend.
  ///
  /// Receives the full [KcAppConfig] so the factory can extract credentials.
  final T Function(KcAppConfig config) createWordPress;

  const KcServiceFactory({required this.createFake, required this.createWordPress});
}
