/**
 * Instance Identity Types
 *
 * Types for federation instance identity model.
 */

import type { FederationConnectionStatus } from "@prisma/client";

/**
 * Capabilities that an instance can support
 */
export interface FederationCapabilities {
  /** Supports QUERY message type */
  supportsQuery?: boolean;
  /** Supports COMMAND message type */
  supportsCommand?: boolean;
  /** Supports EVENT message type */
  supportsEvent?: boolean;
  /** Supports agent spawning */
  supportsAgentSpawn?: boolean;
  /** Supported protocol version */
  protocolVersion?: string;
}

/**
 * Instance identity information
 */
export interface InstanceIdentity {
  /** Internal UUID */
  id: string;
  /** Federation identifier (unique across all instances) */
  instanceId: string;
  /** Display name for this instance */
  name: string;
  /** Base URL for this instance */
  url: string;
  /** RSA public key for signature verification */
  publicKey: string;
  /** Encrypted RSA private key for signing (not exposed in public identity) */
  privateKey?: string;
  /** Capabilities this instance supports */
  capabilities: FederationCapabilities;
  /** Additional metadata */
  metadata: Record<string, unknown>;
  /** Creation timestamp */
  createdAt: Date;
  /** Last update timestamp */
  updatedAt: Date;
}

/**
 * Public instance identity (excludes private key)
 */
export interface PublicInstanceIdentity {
  /** Internal UUID */
  id: string;
  /** Federation identifier */
  instanceId: string;
  /** Display name */
  name: string;
  /** Base URL */
  url: string;
  /** RSA public key */
  publicKey: string;
  /** Capabilities */
  capabilities: FederationCapabilities;
  /** Additional metadata */
  metadata: Record<string, unknown>;
  /** Creation timestamp */
  createdAt: Date;
  /** Last update timestamp */
  updatedAt: Date;
}

/**
 * Federation connection information
 */
export interface FederationConnection {
  /** Internal UUID */
  id: string;
  /** Workspace that owns this connection */
  workspaceId: string;
  /** Remote instance federation ID */
  remoteInstanceId: string;
  /** Remote instance base URL */
  remoteUrl: string;
  /** Remote instance public key */
  remotePublicKey: string;
  /** Remote instance capabilities */
  remoteCapabilities: FederationCapabilities;
  /** Connection status */
  status: FederationConnectionStatus;
  /** Additional metadata */
  metadata: Record<string, unknown>;
  /** Creation timestamp */
  createdAt: Date;
  /** Last update timestamp */
  updatedAt: Date;
  /** Timestamp when connection became active */
  connectedAt: Date | null;
  /** Timestamp when connection was disconnected */
  disconnectedAt: Date | null;
}

/**
 * Key pair for instance signing
 */
export interface KeyPair {
  /** RSA public key (PEM format) */
  publicKey: string;
  /** RSA private key (PEM format) */
  privateKey: string;
}
