import { describe, it, expect } from 'vitest';
import {
  CONDITION_KIND_OPTIONS,
  SEVERITY_OPTIONS,
  ROUTE_METRIC_OPTIONS,
  COMPARATOR_OPTIONS,
  JVM_AGGREGATION_OPTIONS,
  EXCHANGE_FIRE_MODE_OPTIONS,
  TARGET_KIND_OPTIONS,
  AGENT_LIFECYCLE_EVENT_TYPE_OPTIONS,
} from './enums';

/**
 * Snapshot tests for the schema-derived option arrays.
 *
 * A backend enum change (or a hide-list change) will flip one of these
 * snapshots. Reviewing the diff in a PR is the intended signal to confirm
 * the change is intentional. The `Record<T, string>` label maps already
 * enforce exhaustiveness at compile time; these tests enforce the *visible*
 * shape (values, order, hidden items) at review time.
 */

describe('alerts/enums option arrays', () => {
  it('CONDITION_KIND_OPTIONS', () => {
    expect(CONDITION_KIND_OPTIONS).toEqual([
      { value: 'ROUTE_METRIC',     label: 'Route metric (error rate, latency, throughput)' },
      { value: 'EXCHANGE_MATCH',   label: 'Exchange match (specific failures)' },
      { value: 'AGENT_STATE',      label: 'Agent state (DEAD / STALE)' },
      { value: 'AGENT_LIFECYCLE',  label: 'Agent lifecycle (register / restart / stale / dead)' },
      { value: 'DEPLOYMENT_STATE', label: 'Deployment state (FAILED / DEGRADED)' },
      { value: 'LOG_PATTERN',      label: 'Log pattern (count of matching logs)' },
      { value: 'JVM_METRIC',       label: 'JVM metric (heap, GC, inflight)' },
    ]);
  });

  it('AGENT_LIFECYCLE_EVENT_TYPE_OPTIONS', () => {
    expect(AGENT_LIFECYCLE_EVENT_TYPE_OPTIONS).toEqual([
      { value: 'WENT_STALE',    label: 'Went stale (heartbeat missed)' },
      { value: 'WENT_DEAD',     label: 'Went dead (extended silence)' },
      { value: 'RECOVERED',     label: 'Recovered (stale → live)' },
      { value: 'REGISTERED',    label: 'Registered (first check-in)' },
      { value: 'RE_REGISTERED', label: 'Re-registered (app restart)' },
      { value: 'DEREGISTERED',  label: 'Deregistered (graceful shutdown)' },
    ]);
  });

  it('SEVERITY_OPTIONS', () => {
    expect(SEVERITY_OPTIONS).toEqual([
      { value: 'CRITICAL', label: 'Critical' },
      { value: 'WARNING',  label: 'Warning' },
      { value: 'INFO',     label: 'Info' },
    ]);
  });

  it('ROUTE_METRIC_OPTIONS', () => {
    expect(ROUTE_METRIC_OPTIONS).toEqual([
      { value: 'ERROR_RATE',      label: 'Error rate' },
      { value: 'P99_LATENCY_MS',  label: 'P99 latency (ms)' },
      { value: 'AVG_DURATION_MS', label: 'Avg duration (ms)' },
      { value: 'THROUGHPUT',      label: 'Throughput (msg/s)' },
      { value: 'ERROR_COUNT',     label: 'Error count' },
    ]);
  });

  it('COMPARATOR_OPTIONS (EQ is hidden — noisy for float comparisons)', () => {
    expect(COMPARATOR_OPTIONS).toEqual([
      { value: 'GT',  label: '>' },
      { value: 'GTE', label: '\u2265' },
      { value: 'LT',  label: '<' },
      { value: 'LTE', label: '\u2264' },
    ]);
    expect(COMPARATOR_OPTIONS.find((o) => o.value === 'EQ')).toBeUndefined();
  });

  it('JVM_AGGREGATION_OPTIONS (LATEST is hidden — use a dashboard instead)', () => {
    expect(JVM_AGGREGATION_OPTIONS).toEqual([
      { value: 'MAX', label: 'MAX' },
      { value: 'AVG', label: 'AVG' },
      { value: 'MIN', label: 'MIN' },
    ]);
    expect(JVM_AGGREGATION_OPTIONS.find((o) => o.value === 'LATEST')).toBeUndefined();
  });

  it('EXCHANGE_FIRE_MODE_OPTIONS', () => {
    expect(EXCHANGE_FIRE_MODE_OPTIONS).toEqual([
      { value: 'PER_EXCHANGE',    label: 'One alert per matching exchange' },
      { value: 'COUNT_IN_WINDOW', label: 'Threshold: N matches in window' },
    ]);
  });

  it('TARGET_KIND_OPTIONS', () => {
    expect(TARGET_KIND_OPTIONS).toEqual([
      { value: 'USER',  label: 'User' },
      { value: 'GROUP', label: 'Group' },
      { value: 'ROLE',  label: 'Role' },
    ]);
  });
});
