import { describe, test, expect } from 'vitest'

describe('WorkerManagement Page', () => {
  test('page module is importable', async () => {
    const module = await import('../../pages/WorkerManagement')
    expect(module.default).toBeDefined()
  })
})

describe('media API', () => {
  test('getMediaAssets is a function', async () => {
    const { getMediaAssets } = await import('../../api/media')
    expect(typeof getMediaAssets).toBe('function')
  })

  test('MediaFilter supports cad_file_id', () => {
    // Type-level check: build a filter with cad_file_id
    const filter = { cad_file_id: 'some-uuid', asset_type: 'gltf_geometry' as const }
    expect(filter.cad_file_id).toBe('some-uuid')
  })

  test('MediaAsset interface has all required fields', () => {
    const asset = {
      id: 'uuid',
      tenant_id: null,
      product_id: null,
      cad_file_id: null,
      order_line_id: null,
      workflow_run_id: null,
      asset_type: 'still' as const,
      storage_key: 'path/to/file.png',
      file_size_bytes: 1024,
      mime_type: 'image/png',
      width: 512,
      height: 512,
      duration_s: null,
      render_config: null,
      is_archived: false,
      created_at: new Date().toISOString(),
      download_url: null,
    }
    expect(asset.asset_type).toBe('still')
    expect(asset.cad_file_id).toBeNull()
  })
})

describe('cad API', () => {
  test('generateGltfGeometry is a function', async () => {
    const { generateGltfGeometry } = await import('../../api/cad')
    expect(typeof generateGltfGeometry).toBe('function')
  })

  test('getCadThumbnailUrl returns correct URL', async () => {
    const { getCadThumbnailUrl } = await import('../../api/cad')
    const url = getCadThumbnailUrl('test-uuid')
    expect(url).toBe('/api/cad/test-uuid/thumbnail')
  })
})

describe('Scale request validation', () => {
  test('allowed services', () => {
    const allowed = ['render-worker', 'worker', 'worker-thumbnail']
    expect(allowed).toContain('render-worker')
    expect(allowed).toContain('worker-thumbnail')
    expect(allowed).not.toContain('postgres')
  })
})
