import 'inventory_status.dart';
import 'inventory_sync_status.dart';

/// A single inventory item tracked by the Kell Creations operations platform.
class InventoryItem {
  final String id;
  final String sku;
  final String name;
  final String description;
  final String imageUrl;
  final String category;
  final int quantityOnHand;
  final double unitPrice;
  final int reorderPoint;
  final String? supplier;
  final String? location;
  final InventoryStatus status;
  final DateTime lastUpdated;

  // ── WooCommerce sync fields ────────────────────────────────────────────────

  /// The WooCommerce product ID linked to this inventory item.
  ///
  /// `null` if this item has no WooCommerce counterpart (e.g. raw materials,
  /// packaging, or items not listed in the online store).
  final int? wooCommerceProductId;

  /// The timestamp of the last successful sync with WooCommerce.
  ///
  /// `null` if the item has never been synced.
  final DateTime? lastSyncedAt;

  /// The current synchronization state with WooCommerce.
  ///
  /// Defaults to [InventorySyncStatus.notSynced] for items without a
  /// WooCommerce product ID.
  final InventorySyncStatus syncStatus;

  const InventoryItem({
    required this.id,
    required this.sku,
    required this.name,
    required this.description,
    required this.imageUrl,
    required this.category,
    required this.quantityOnHand,
    required this.unitPrice,
    required this.reorderPoint,
    this.supplier,
    this.location,
    required this.status,
    required this.lastUpdated,
    this.wooCommerceProductId,
    this.lastSyncedAt,
    this.syncStatus = InventorySyncStatus.notSynced,
  });

  /// Returns a copy of this [InventoryItem] with the given fields replaced.
  InventoryItem copyWith({
    String? id,
    String? sku,
    String? name,
    String? description,
    String? imageUrl,
    String? category,
    int? quantityOnHand,
    double? unitPrice,
    int? reorderPoint,
    String? supplier,
    String? location,
    InventoryStatus? status,
    DateTime? lastUpdated,
    int? wooCommerceProductId,
    DateTime? lastSyncedAt,
    InventorySyncStatus? syncStatus,
  }) {
    return InventoryItem(
      id: id ?? this.id,
      sku: sku ?? this.sku,
      name: name ?? this.name,
      description: description ?? this.description,
      imageUrl: imageUrl ?? this.imageUrl,
      category: category ?? this.category,
      quantityOnHand: quantityOnHand ?? this.quantityOnHand,
      unitPrice: unitPrice ?? this.unitPrice,
      reorderPoint: reorderPoint ?? this.reorderPoint,
      supplier: supplier ?? this.supplier,
      location: location ?? this.location,
      status: status ?? this.status,
      lastUpdated: lastUpdated ?? this.lastUpdated,
      wooCommerceProductId: wooCommerceProductId ?? this.wooCommerceProductId,
      lastSyncedAt: lastSyncedAt ?? this.lastSyncedAt,
      syncStatus: syncStatus ?? this.syncStatus,
    );
  }
}
