import { describe, it, expect, beforeEach } from 'vitest'
import { useEngineStore } from '../store/engineStore'

describe('engineStore', () => {
  beforeEach(() => {
    useEngineStore.setState({
      status: 'Idle',
      uptime_seconds: 0,
      total_scanned: 0,
      total_alerts: 0,
      last_cycle: 'Never',
      isOffline: false,
    })
  })

  it('initial state is Idle', () => {
    expect(useEngineStore.getState().status).toBe('Idle')
  })

  it('setStats updates all fields', () => {
    useEngineStore.getState().setStats({
      engine_status: 'Running',
      uptime_seconds: 120,
      total_scanned: 42,
      total_alerts: 3,
      last_cycle: '2026-03-11T10:00:00',
      uptime_start: Date.now() / 1000,
    })
    const s = useEngineStore.getState()
    expect(s.status).toBe('Running')
    expect(s.total_scanned).toBe(42)
  })

  it('setOffline marks isOffline true', () => {
    useEngineStore.getState().setOffline(true)
    expect(useEngineStore.getState().isOffline).toBe(true)
  })
})
