import { describe, it, expect } from 'vitest';

describe('Notification Dispatcher', () => {
  const SEVERITY_ORDER: Record<string, number> = { critical: 5, high: 4, medium: 3, low: 2, info: 1 };

  it('dispatches to channels meeting severity threshold', () => {
    const incidentSeverity = 'high';
    const channelMinSeverity = 'medium';

    const incidentLevel = SEVERITY_ORDER[incidentSeverity] ?? 0;
    const minLevel = SEVERITY_ORDER[channelMinSeverity] ?? 0;

    expect(incidentLevel >= minLevel).toBe(true);
  });

  it('skips channels below severity threshold', () => {
    const incidentSeverity = 'low';
    const channelMinSeverity = 'high';

    const incidentLevel = SEVERITY_ORDER[incidentSeverity] ?? 0;
    const minLevel = SEVERITY_ORDER[channelMinSeverity] ?? 0;

    expect(incidentLevel >= minLevel).toBe(false);
  });

  it('critical always dispatches', () => {
    const incidentLevel = SEVERITY_ORDER['critical']!;
    for (const [, minLevel] of Object.entries(SEVERITY_ORDER)) {
      expect(incidentLevel >= minLevel).toBe(true);
    }
  });

  it('info only dispatches to info channels', () => {
    const incidentLevel = SEVERITY_ORDER['info']!;
    expect(incidentLevel >= SEVERITY_ORDER['info']!).toBe(true);
    expect(incidentLevel >= SEVERITY_ORDER['low']!).toBe(false);
  });
});

describe('Slack Block Kit Builder', () => {
  it('maps severity to emoji', () => {
    const emojiMap: Record<string, string> = {
      critical: '🔴', high: '🟠', medium: '🟡', low: '🔵', info: 'ℹ️',
    };

    expect(emojiMap['critical']).toBe('🔴');
    expect(emojiMap['high']).toBe('🟠');
    expect(emojiMap['unknown']).toBeUndefined();
  });

  it('includes action buttons', () => {
    const actions = ['view_incident', 'ack_incident', 'suppress_incident'];
    expect(actions).toHaveLength(3);
    expect(actions).toContain('ack_incident');
  });
});
