// SolaceNet Event Definitions
// Event types for capability lifecycle events

import { EventEmitter } from 'events';

export interface CapabilityEnabledEvent {
  capabilityId: string;
  tenantId?: string;
  programId?: string;
  region?: string;
  channel?: string;
  actor: string;
  timestamp: Date;
}

export interface CapabilityDisabledEvent {
  capabilityId: string;
  tenantId?: string;
  programId?: string;
  region?: string;
  channel?: string;
  actor: string;
  reason?: string;
  timestamp: Date;
}

export interface CapabilityToggledEvent {
  capabilityId: string;
  beforeState: string;
  afterState: string;
  tenantId?: string;
  programId?: string;
  region?: string;
  channel?: string;
  actor: string;
  reason?: string;
  timestamp: Date;
}

export interface PolicyDecisionEvent {
  decisionId: string;
  capabilityId: string;
  tenantId: string;
  programId?: string;
  allowed: boolean;
  mode: string;
  reasonCode?: string;
  timestamp: Date;
}

export interface KillSwitchActivatedEvent {
  capabilityId: string;
  actor: string;
  reason?: string;
  timestamp: Date;
}

// Event emitter for SolaceNet events
export const solacenetEventEmitter = new EventEmitter();

// Event type constants
export const SOLACENET_EVENTS = {
  CAPABILITY_ENABLED: 'capability.enabled',
  CAPABILITY_DISABLED: 'capability.disabled',
  CAPABILITY_TOGGLED: 'capability.toggled',
  POLICY_DECISION: 'policy.decision',
  KILL_SWITCH_ACTIVATED: 'kill-switch.activated',
} as const;

/**
 * Emit capability enabled event
 */
export function emitCapabilityEnabled(event: CapabilityEnabledEvent): void {
  solacenetEventEmitter.emit(SOLACENET_EVENTS.CAPABILITY_ENABLED, event);
}

/**
 * Emit capability disabled event
 */
export function emitCapabilityDisabled(event: CapabilityDisabledEvent): void {
  solacenetEventEmitter.emit(SOLACENET_EVENTS.CAPABILITY_DISABLED, event);
}

/**
 * Emit capability toggled event
 */
export function emitCapabilityToggled(event: CapabilityToggledEvent): void {
  solacenetEventEmitter.emit(SOLACENET_EVENTS.CAPABILITY_TOGGLED, event);
}

/**
 * Emit policy decision event
 */
export function emitPolicyDecision(event: PolicyDecisionEvent): void {
  solacenetEventEmitter.emit(SOLACENET_EVENTS.POLICY_DECISION, event);
}

/**
 * Emit kill switch activated event
 */
export function emitKillSwitchActivated(event: KillSwitchActivatedEvent): void {
  solacenetEventEmitter.emit(SOLACENET_EVENTS.KILL_SWITCH_ACTIVATED, event);
}
