/// A generic product representation used for cross-channel data exchange.
///
/// This is intentionally minimal — channel adapters map between this
/// neutral format and their platform-specific models.
class ChannelProduct {
  final String id;
  final String name;
  final double price;
  final String status;
  final String? description;
  final String? sku;
  final String? imageUrl;
  final String? category;

  const ChannelProduct({
    required this.id,
    required this.name,
    required this.price,
    required this.status,
    this.description,
    this.sku,
    this.imageUrl,
    this.category,
  });
}

/// A generic order representation used for cross-channel data exchange.
class ChannelOrder {
  final String id;
  final String status;
  final double total;
  final String? customerName;
  final String? customerEmail;
  final List<ChannelOrderItem> items;

  const ChannelOrder({
    required this.id,
    required this.status,
    required this.total,
    this.customerName,
    this.customerEmail,
    this.items = const [],
  });
}

/// A single line item within a [ChannelOrder].
class ChannelOrderItem {
  final String productId;
  final String name;
  final int quantity;
  final double unitPrice;

  const ChannelOrderItem({
    required this.productId,
    required this.name,
    required this.quantity,
    required this.unitPrice,
  });
}

/// A generic inventory count used for cross-channel data exchange.
class ChannelInventoryCount {
  final String productId;
  final String? sku;
  final int quantity;

  const ChannelInventoryCount({required this.productId, this.sku, required this.quantity});
}

/// The abstraction for a sales channel (WooCommerce, Square, future channels).
///
/// Each channel adapter provides a standard set of operations — products,
/// orders, and inventory — so the application layer can interact with any
/// channel through a single interface without knowing platform-specific
/// details.
///
/// Concrete implementations live in their respective data layers and are
/// selected at runtime via `--dart-define`.
abstract class ChannelAdapter {
  /// A stable identifier for this channel (e.g. `'woocommerce'`, `'square'`).
  String get channelId;

  /// Human-readable display name for this channel.
  String get displayName;

  // ── Products ──────────────────────────────────────────────────────────────

  /// Fetches all products from the channel.
  Future<List<ChannelProduct>> getProducts();

  /// Fetches a single product by its channel-specific [id].
  Future<ChannelProduct> getProduct(String id);

  /// Updates a product on the channel.
  ///
  /// Only the fields present in [updates] are changed; others are left as-is.
  Future<ChannelProduct> updateProduct(String id, Map<String, dynamic> updates);

  // ── Orders ────────────────────────────────────────────────────────────────

  /// Fetches all orders from the channel.
  Future<List<ChannelOrder>> getOrders();

  /// Fetches a single order by its channel-specific [id].
  Future<ChannelOrder> getOrder(String id);

  /// Updates the status of an order on the channel.
  Future<ChannelOrder> updateOrderStatus(String id, String status);

  // ── Inventory ─────────────────────────────────────────────────────────────

  /// Fetches inventory counts for all products on the channel.
  Future<List<ChannelInventoryCount>> getInventoryCounts();

  /// Updates the stock quantity for a product on the channel.
  Future<ChannelInventoryCount> updateInventoryCount(String productId, int quantity);
}
