export type StockState = 'available' | 'reserved' | 'sold' | 'incoming';

/**
 * Well-known UUID of the default store seeded by migration 043 and used by
 * the legacy ecommerce flow. Multi-store terminals pass their own storeId;
 * the ecommerce flow passes this constant.
 */
export const DEFAULT_STORE_ID = '00000000-0000-0000-0000-000000000001';

export interface StockItem {
  id: string;
  variantId: string;
  storeId: string;
  available: number;
  reserved: number;
  sold: number;
  incoming: number;
  createdAt: Date;
  updatedAt: Date;
}

export interface StockCommand {
  variantId: string;
  storeId: string;
  quantity: number;
}

export type SetAvailableStockCommand = StockCommand;

export interface Availability {
  available: boolean;
  availableQuantity: number;
}

export function assertPositiveQuantity(quantity: number): void {
  if (!Number.isInteger(quantity) || quantity <= 0) {
    throw new Error('Stock quantity must be a positive integer');
  }
}
