import { describe, expect, it } from 'vitest'
import { holdingsResponseSchema, mismatchesResponseSchema } from '../schema'

const id = '550e8400-e29b-41d4-a716-446655440001'

describe('reconciliation API contracts', () => {
  it('accepts the holdings response emitted by the current endpoint', () => {
    expect(holdingsResponseSchema.safeParse({
      items: [{ id, securityId: id, quantity: 10, weightedAvgCost: 100, totalCostBasis: 1000, marketValue: 1100, unrealizedGainLoss: 100, updatedAt: '2026-08-12T00:00:00Z', correlationId: id }],
      total: 1,
      pages: 1
    }).success).toBe(true)
  })

  it('rejects a mismatch response with an invalid timestamp', () => {
    expect(mismatchesResponseSchema.safeParse({
      items: [{ id, tradeId: id, holdingId: id, mismatchReason: null, quantityBefore: 10, quantityAfter: 9, costBasisDelta: -100, detectedAt: 'not-a-date' }],
      total: 1,
      pages: 1
    }).success).toBe(false)
  })

  it('rejects a negative response total', () => {
    expect(holdingsResponseSchema.safeParse({ items: [], total: -1, pages: 1 }).success).toBe(false)
  })
})
