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

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

describe('worker API types', () => {
  test('WorkerActivity interface shape', async () => {
    // Type-level check: the interface must have the right keys
    const activity = {
      cad_processing: [],
      active_count: 0,
      failed_count: 0,
      render_jobs: [],
      render_active_count: 0,
      render_failed_count: 0,
    }
    expect(activity.cad_processing).toBeInstanceOf(Array)
    expect(typeof activity.active_count).toBe('number')
  })

  test('CeleryWorker interface shape', () => {
    const worker = {
      name: 'celery@worker1',
      queues: ['thumbnail_rendering'],
      active_task_count: 2,
      active_tasks: [{ name: 'render_still_task', id: 'abc' }],
      total_tasks_processed: { render_still_task: 42 },
    }
    expect(worker.queues).toContain('thumbnail_rendering')
    expect(worker.active_tasks).toHaveLength(1)
  })

  test('QueueStatus interface shape', () => {
    const qs = {
      queue_depths: { step_processing: 3, thumbnail_rendering: 0 },
      pending_count: 3,
      active: [],
      reserved: [],
      pending: [],
    }
    expect(qs.queue_depths).toHaveProperty('step_processing')
    expect(qs.pending_count).toBe(3)
  })
})

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

  test('getCeleryWorkers is a function', async () => {
    const { getCeleryWorkers } = await import('../../api/worker')
    expect(typeof getCeleryWorkers).toBe('function')
  })

  test('scaleWorkers is a function', async () => {
    const { scaleWorkers } = await import('../../api/worker')
    expect(typeof scaleWorkers).toBe('function')
  })

  test('getQueueStatus is a function', async () => {
    const { getQueueStatus } = await import('../../api/worker')
    expect(typeof getQueueStatus).toBe('function')
  })
})
