import {
  isImmutableFieldError,
  isNoPriceForCurrencyError,
  isProductValidationError,
} from '@platform-modules/commerce-catalog'

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

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

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