export interface BaseEvent {
  id: string;
  tenantId: string;
  timestamp: Date;
  source: string;
}

export interface CommandExecutedEvent extends BaseEvent {
  type: 'command.executed';
  payload: {
    sessionId: string;
    command: string;
    riskLevel: number;
    output: string;
  };
}

export interface ApprovalRequiredEvent extends BaseEvent {
  type: 'approval.required';
  payload: {
    taskId: string;
    command: string;
    riskLevel: number;
    targetServer: string;
    expiresAt: Date;
  };
}

export interface AlertFiredEvent extends BaseEvent {
  type: 'alert.fired';
  payload: {
    ruleId: string;
    serverId: string;
    severity: 'info' | 'warning' | 'critical' | 'fatal';
    message: string;
    metricValue: number;
  };
}

export interface TaskCompletedEvent extends BaseEvent {
  type: 'task.completed';
  payload: {
    taskId: string;
    result: 'success' | 'failure' | 'partial';
    summary: string;
  };
}

export interface StandingOrderExecutedEvent extends BaseEvent {
  type: 'standing.order.executed';
  payload: {
    orderId: string;
    executionId: string;
    status: 'completed' | 'failed' | 'awaiting_human';
    summary?: string;
  };
}

export interface UsageRecordedEvent extends BaseEvent {
  type: 'usage.recorded';
  payload: {
    taskId: string;
    sessionId: string;
    engineType: string;
    inputTokens: number;
    outputTokens: number;
    totalTokens: number;
    costUsd: number;
    model: string;
  };
}

export interface SubscriptionChangedEvent extends BaseEvent {
  type: 'subscription.changed';
  payload: {
    subscriptionId: string;
    fromPlan: string;
    toPlan: string;
    status: string;
  };
}

export interface QuotaExceededEvent extends BaseEvent {
  type: 'quota.exceeded';
  payload: {
    quotaType: 'tokens' | 'servers' | 'users' | 'standing_orders';
    current: number;
    limit: number;
  };
}

export interface PaymentReceivedEvent extends BaseEvent {
  type: 'payment.received';
  payload: {
    invoiceId: string;
    paymentId: string;
    amount: number;
    currency: string;
    provider: string;
  };
}

export type IT0Event =
  | CommandExecutedEvent
  | ApprovalRequiredEvent
  | AlertFiredEvent
  | TaskCompletedEvent
  | StandingOrderExecutedEvent
  | UsageRecordedEvent
  | SubscriptionChangedEvent
  | QuotaExceededEvent
  | PaymentReceivedEvent;
