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

describe('@platform-modules/commerce-promotions public barrel', () => {
  it('exports every named core symbol', () => {
    for (const name of [
      'PromoValidationError',
      'PromoQuotaExhaustedError',
      'PromoMigrateError',
      'isPromoValidationError',
      'isPromoQuotaExhaustedError',
      'isPromoMigrateError',
      'validatePromo',
      'applyPromo',
      'getPromoByCode',
      'recordRedemption',
      'pushSchema',
      'promo',
      'promoUserUsage',
      'promotionsSchema',
    ]) {
      expect(promotions, `missing export: ${name}`).toHaveProperty(name)
      expect((promotions as Record<string, unknown>)[name], `${name} is undefined`).toBeDefined()
    }

    expect(typeof promotions.validatePromo).toBe('function')
    expect(typeof promotions.applyPromo).toBe('function')
    expect(typeof promotions.getPromoByCode).toBe('function')
    expect(typeof promotions.recordRedemption).toBe('function')
    expect(typeof promotions.pushSchema).toBe('function')

    expect(promotions.isPromoValidationError(new promotions.PromoValidationError('valueBps'))).toBe(
      true,
    )
    expect(
      promotions.isPromoQuotaExhaustedError(new promotions.PromoQuotaExhaustedError('global')),
    ).toBe(true)
    expect(promotions.isPromoMigrateError(new promotions.PromoMigrateError('x'))).toBe(true)
  })
})
