import { describe, expect, it } from 'vitest'
import { z } from 'zod'
import { catalogTools } from './catalog.js'

describe('catalogTools stock switch', () => {
  it('drops the stock tool, stock filter and stock issue type when stock is not managed', () => {
    const off = catalogTools({ stock: false })
    expect(off.map(t => t.name)).not.toContain('get_stock')
    expect(off.find(t => t.name === 'search_products')!.input).not.toHaveProperty('in_stock')
    const issue = off.find(t => t.name === 'find_products_with_issues')!.input.issue as z.ZodEnum
    expect(issue.options).not.toContain('out_of_stock_enabled')
    expect(off.every(t => !/stock/i.test(t.description) || t.name === 'search_products')).toBe(true)
  })

  it('keeps them when stock is managed', () => {
    const on = catalogTools({ stock: true })
    expect(on.map(t => t.name)).toContain('get_stock')
    expect((on.find(t => t.name === 'find_products_with_issues')!.input.issue as z.ZodEnum).options).toContain('out_of_stock_enabled')
  })
})
