/**
 * TypeScript interfaces for the A2A (Agent-to-Agent) delegation subsystem.
 * All delegation types are defined here — no inline type definitions in services or controllers.
 */

/** A delegation chain record as stored in the database. */
export interface DelegationChain {
  id: string;
  tenantId: string;
  delegatorAgentId: string;
  delegateeAgentId: string;
  scopes: string[];
  delegationToken: string;
  signature: string;
  ttlSeconds: number;
  issuedAt: Date;
  expiresAt: Date;
  revokedAt: Date | null;
  createdAt: Date;
}

/** Request body for creating a new delegation. */
export interface CreateDelegationRequest {
  /** UUID of the agent receiving delegated authority. Must be in the same tenant. */
  delegateeAgentId: string;
  /** Scopes to delegate. Must be a strict subset of the delegator's own scopes. */
  scopes: string[];
  /** Delegation lifetime in seconds. Min: 60, Max: 86400. */
  ttlSeconds: number;
}

/** Result of verifying a delegation token. Never throws on expired/revoked — returns valid: false. */
export interface DelegationVerificationResult {
  valid: boolean;
  chainId: string;
  delegatorAgentId: string;
  delegateeAgentId: string;
  scopes: string[];
  issuedAt: Date;
  expiresAt: Date;
  revokedAt: Date | null;
}

/** Payload signed by HMAC-SHA256 to produce the delegation signature. */
export interface DelegationTokenPayload {
  chainId: string;
  tenantId: string;
  delegatorAgentId: string;
  delegateeAgentId: string;
  scopes: string[];
  issuedAt: string; // ISO 8601
  expiresAt: string; // ISO 8601
}
