import { test } from '@japa/runner'
import { ApiSchemaValues } from '../../../src/amf/ApiSchemaValues.js'
import { IAmfDocument } from '../../../src/amf/definitions/Amf.js'
import { IApiScalarShape } from '../../../src/amf/definitions/Shapes.js'
import { AmfLoader } from './AmfLoader.js'

test.group('APIC-689', (group) => {
  const apiFile = 'APIC-689'
  const loader = new AmfLoader()

  let model: IAmfDocument

  group.setup(async () => {
    model = await loader.getGraph(apiFile)
  })

  test('does not set URL query param for an optional enum', async ({ assert }) => {
    const param = loader.getParameter(model, '/test', 'get', 'param1')
    const result = ApiSchemaValues.readInputValue(param, param.schema as IApiScalarShape, { requiredOnly: true })
    assert.isUndefined(result, 'has the empty default value (from schema type)')
  })

  test('returns the first enum value', async ({ assert }) => {
    const param = loader.getParameter(model, '/test', 'post', 'param1')
    const result = ApiSchemaValues.readInputValue(param, param.schema as IApiScalarShape, { requiredOnly: true })
    assert.equal(result, 'A', 'has the first enum type')
  })
})
