/**
 * Model Info Tests
 * Verifies model registrations in MODEL_INFO and provider config schemas
 */

import { describe, it, expect } from 'vitest'
import { AnthropicConfigSchema, MODEL_INFO, GoogleConfigSchema } from '../model-info'

describe('gemini-3.1-flash-lite-preview registration', () => {
  it('exists in MODEL_INFO with correct pricing', () => {
    const info = MODEL_INFO['gemini-3.1-flash-lite-preview']
    expect(info).toBeDefined()
    expect(info.inputCostPer1M).toBe(25)
    expect(info.outputCostPer1M).toBe(150)
  })

  it('GoogleConfigSchema validates a config with gemini-3.1-flash-lite-preview', () => {
    const result = GoogleConfigSchema.safeParse({
      model: 'gemini-3.1-flash-lite-preview',
      provider: 'google',
      apiKey: 'test-key'
    })
    expect(result.success).toBe(true)
  })

  it('GoogleConfigSchema validates temperature: 0 for Flash-Lite', () => {
    const result = GoogleConfigSchema.safeParse({
      model: 'gemini-3.1-flash-lite-preview',
      provider: 'google',
      apiKey: 'test-key',
      temperature: 0
    })
    expect(result.success).toBe(true)
  })

  it('GoogleConfigSchema validates temperature: 1 for Flash', () => {
    const result = GoogleConfigSchema.safeParse({
      model: 'gemini-3-flash-preview',
      provider: 'google',
      apiKey: 'test-key',
      temperature: 1
    })
    expect(result.success).toBe(true)
  })

  it('GoogleModel type includes gemini-3.1-flash-lite-preview via MODEL_INFO key check', () => {
    const modelKeys = Object.keys(MODEL_INFO)
    expect(modelKeys).toContain('gemini-3.1-flash-lite-preview')
  })
})

describe('current Anthropic model registration', () => {
  it('registers Opus 4.8 with current pricing and token limits', () => {
    const info = MODEL_INFO['claude-opus-4-8']

    expect(info).toBeDefined()
    expect(info.inputCostPer1M).toBe(500)
    expect(info.outputCostPer1M).toBe(2500)
    expect(info.maxTokens).toBe(1000000)
    expect(info.maxOutputTokens).toBe(128000)
  })

  it('registers Sonnet 4.6 with current pricing and token limits', () => {
    const info = MODEL_INFO['claude-sonnet-4-6']

    expect(info).toBeDefined()
    expect(info.inputCostPer1M).toBe(300)
    expect(info.outputCostPer1M).toBe(1500)
    expect(info.maxTokens).toBe(1000000)
    expect(info.maxOutputTokens).toBe(64000)
  })

  it('registers Haiku 4.5 dated ID and alias with current pricing and token limits', () => {
    const datedInfo = MODEL_INFO['claude-haiku-4-5-20251001']
    const aliasInfo = MODEL_INFO['claude-haiku-4-5']

    expect(datedInfo).toBeDefined()
    expect(aliasInfo).toBeDefined()
    expect(datedInfo.inputCostPer1M).toBe(100)
    expect(datedInfo.outputCostPer1M).toBe(500)
    expect(datedInfo.maxTokens).toBe(200000)
    expect(datedInfo.maxOutputTokens).toBe(64000)
    expect(aliasInfo).toMatchObject({
      inputCostPer1M: datedInfo.inputCostPer1M,
      outputCostPer1M: datedInfo.outputCostPer1M,
      maxTokens: datedInfo.maxTokens,
      maxOutputTokens: datedInfo.maxOutputTokens
    })
  })

  it.each(['claude-opus-4-8', 'claude-sonnet-4-6', 'claude-haiku-4-5-20251001', 'claude-haiku-4-5'])(
    'AnthropicConfigSchema validates %s',
    (model) => {
      const result = AnthropicConfigSchema.safeParse({
        model,
        provider: 'anthropic',
        apiKey: 'test-key',
        maxOutputTokens: 4000
      })

      expect(result.success).toBe(true)
    }
  )

  it('rejects non-default Opus 4.8 sampling parameters', () => {
    const temperatureResult = AnthropicConfigSchema.safeParse({
      model: 'claude-opus-4-8',
      provider: 'anthropic',
      apiKey: 'test-key',
      temperature: 0.7
    })

    const topPResult = AnthropicConfigSchema.safeParse({
      model: 'claude-opus-4-8',
      provider: 'anthropic',
      apiKey: 'test-key',
      topP: 0.9
    })

    expect(temperatureResult.success).toBe(false)
    expect(topPResult.success).toBe(false)
  })
})
