import { describe, expect, it } from 'vitest'
import {
  CartProviderError,
  CartWireError,
  isCartProviderError,
  isCartWireError,
  isCartValidationError,
  isMixedCurrencyError,
} from './errors.js'

describe('CartProviderError', () => {
  it('names the hook + is identified structurally (not instanceof)', () => {
    const e = new CartProviderError('useCart')
    expect(e.name).toBe('CartProviderError')
    expect(e.message).toContain('useCart')
    expect(isCartProviderError(e)).toBe(true)
    // structural guard matches a cross-realm copy (no instanceof)
    expect(isCartProviderError({ name: 'CartProviderError' })).toBe(true)
    expect(isCartProviderError(new Error('x'))).toBe(false)
    expect(isCartProviderError(null)).toBe(false)
  })
})

describe('CartWireError', () => {
  it('carries the message + is identified structurally', () => {
    const e = new CartWireError('bad amount')
    expect(e.name).toBe('CartWireError')
    expect(e.message).toBe('bad amount')
    expect(isCartWireError(e)).toBe(true)
    expect(isCartWireError({ name: 'CartWireError' })).toBe(true)
    expect(isCartWireError(new Error('x'))).toBe(false)
  })
})

describe('re-exported core guards', () => {
  it('are present (consumers branch on error kind without instanceof)', () => {
    expect(typeof isCartValidationError).toBe('function')
    expect(typeof isMixedCurrencyError).toBe('function')
  })
})