import { describe, it, expect } from 'vitest'
import { z } from 'zod'
import { convertContractToJson } from '../utils'
import type { ContractStructure as _ContractStructure } from '../types'

describe('convertContractToJson', () => {

  it('handles complex nested schemas', () => {
    const inputSchema = z.object({
      user: z.object({
        name: z.string(),
        age: z.number(),
        tags: z.array(z.string())
      }),
      metadata: z.record(z.string(), z.unknown())
    })

    const outputSchema = z.object({
      success: z.boolean(),
      data: z.object({
        userId: z.string(),
        createdAt: z.string()
      }).optional()
    })

    const result = convertContractToJson(inputSchema, outputSchema, 'complex-workflow')

    // Verify structure is created with correct definition names
    const inputJsonSchema = result.inputSchema as Record<string, unknown>
    const outputJsonSchema = result.outputSchema as Record<string, unknown>

    expect((inputJsonSchema as { $ref: string }).$ref).toBe('#/definitions/complex-workflow-input')
    expect((outputJsonSchema as { $ref: string }).$ref).toBe('#/definitions/complex-workflow-output')

    // Verify nested properties exist in JSON Schema definitions
    const inputDef = (inputJsonSchema.definitions as Record<string, unknown>)['complex-workflow-input'] as Record<string, unknown>
    expect(inputDef.properties).toHaveProperty('user')
    expect(inputDef.properties).toHaveProperty('metadata')

    const outputDef = (outputJsonSchema.definitions as Record<string, unknown>)['complex-workflow-output'] as Record<string, unknown>
    expect(outputDef.properties).toHaveProperty('success')
    expect(outputDef.properties).toHaveProperty('data')
  })

})
