import {
  isCartValidationError,
  isMixedCurrencyError,
} from '@platform-modules/commerce-cart'

/** Thrown when a cart hook is used outside <CartProvider> (§2). */
export class CartProviderError extends Error {
  override readonly name = 'CartProviderError'
  constructor(hook: string) {
    super(`${hook} must be used within <CartProvider>`)
  }
}
export function isCartProviderError(e: unknown): e is CartProviderError {
  return typeof e === 'object' && e !== null && (e as { name?: string }).name === 'CartProviderError'
}

/** Thrown by reviveCart on malformed serialized wire input (§5). */
export class CartWireError extends Error {
  override readonly name = 'CartWireError'
  constructor(message: string) {
    super(message)
  }
}
export function isCartWireError(e: unknown): e is CartWireError {
  return typeof e === 'object' && e !== null && (e as { name?: string }).name === 'CartWireError'
}

// Re-export the core's structural guards so consumers branch on error kind without instanceof (§4).
export { isCartValidationError, isMixedCurrencyError }