import { describe, expect, it } from 'vitest'
import * as inventory from './index.js'

describe('@platform-modules/commerce-inventory public barrel', () => {
  it('exports every named public symbol', () => {
    for (const name of [
      'OversoldError',
      'InventoryValidationError',
      'InventoryItemNotFoundError',
      'InventoryMigrateError',
      'isOversoldError',
      'isInventoryValidationError',
      'isInventoryItemNotFoundError',
      'isInventoryMigrateError',
      'pushSchema',
      'setInventory',
      'reserve',
      'consume',
      'release',
      'commitStock',
      'getAvailability',
      'sweepStaleReservations',
      'inventoryItem',
      'stockReservation',
      'inventorySchema',
    ]) {
      expect(inventory, `missing export: ${name}`).toHaveProperty(name)
      expect((inventory as Record<string, unknown>)[name], `${name} is undefined`).toBeDefined()
    }

    expect(typeof inventory.setInventory).toBe('function')
    expect(typeof inventory.reserve).toBe('function')
    expect(typeof inventory.consume).toBe('function')
    expect(typeof inventory.release).toBe('function')
    expect(typeof inventory.commitStock).toBe('function')
    expect(typeof inventory.getAvailability).toBe('function')
    expect(typeof inventory.sweepStaleReservations).toBe('function')
    expect(typeof inventory.pushSchema).toBe('function')
    expect(inventory.isOversoldError(new inventory.OversoldError('x', 1))).toBe(true)
    expect(inventory.isInventoryValidationError(new inventory.InventoryValidationError('x'))).toBe(
      true,
    )
    expect(
      inventory.isInventoryItemNotFoundError(new inventory.InventoryItemNotFoundError('x')),
    ).toBe(true)
    expect(inventory.isInventoryMigrateError(new inventory.InventoryMigrateError('x'))).toBe(true)
  })
})
