import { describe, expect, it } from 'vitest'
import { reviveOrderPage, reviveProduct } from './index.js'

// §5: the composed revive helpers MUST be reachable from the marketplace-react
// barrel so a host revives vendor order lists / product rows without importing
// the orders-react / catalog-react siblings directly. These assert the re-export
// is wired (the helpers' own deep behavior is covered in their home siblings).

describe('composed revive helpers re-exported from the barrel (§5)', () => {
  it('reviveProduct is re-exported and revives a wire product', () => {
    expect(typeof reviveProduct).toBe('function')
    const wire = {
      id: 'p1',
      kind: 'physical',
      vendorId: null,
      slug: 'tee',
      title: 'Tee',
      status: 'active',
      media: [{ key: 'm1', alt: 'a' }],
      tags: ['x'],
      availableFrom: '2026-01-01T00:00:00.000Z',
      availableUntil: null,
      createdAt: '2026-06-01T12:00:00.000Z',
      updatedAt: '2026-06-02T12:00:00.000Z',
      variants: [
        {
          id: 'v1',
          productId: 'p1',
          sku: 'S',
          attributes: {},
          prices: [{ currency: 'USD', amount: '1999', priceMode: 'exclusive' }],
        },
      ],
    }
    const product = reviveProduct(wire)
    expect(product.id).toBe('p1')
    expect(product.createdAt).toBeInstanceOf(Date)
  })

  it('reviveOrderPage is re-exported and revives a wire order page', () => {
    expect(typeof reviveOrderPage).toBe('function')
    const page = reviveOrderPage({ items: [], nextCursor: null })
    expect(page.items).toEqual([])
    expect(page.nextCursor).toBeNull()
  })
})
