/**
 * Usage Budget Management types
 *
 * Defines types for tracking and enforcing agent usage budgets
 * including token limits, cost caps, and time-based constraints.
 */

export interface UsageBudget {
  /** Daily token limit across all agents */
  dailyTokenLimit: number;
  /** Per-agent token limit per task */
  perAgentTokenLimit: number;
  /** Maximum concurrent agents */
  maxConcurrentAgents: number;
  /** Maximum task duration in minutes */
  maxTaskDurationMinutes: number;
  /** Whether to hard-stop agents exceeding budget */
  enforceHardLimits: boolean;
}

export interface UsageRecord {
  /** Agent that consumed tokens */
  agentId: string;
  /** Task being worked on */
  taskId: string;
  /** Number of input tokens used */
  inputTokens: number;
  /** Number of output tokens used */
  outputTokens: number;
  /** Timestamp of usage */
  timestamp: Date;
}

export interface UsageSummary {
  /** Total tokens used today */
  dailyTokensUsed: number;
  /** Daily token limit */
  dailyTokenLimit: number;
  /** Percentage of daily budget used */
  dailyUsagePercent: number;
  /** Per-agent usage breakdown */
  agentUsage: AgentUsageSummary[];
  /** Number of currently active agents */
  activeAgents: number;
  /** Maximum concurrent agents allowed */
  maxConcurrentAgents: number;
  /** Whether any budget thresholds are approaching */
  budgetStatus: BudgetStatus;
}

export interface AgentUsageSummary {
  agentId: string;
  taskId: string;
  inputTokens: number;
  outputTokens: number;
  totalTokens: number;
  /** Percentage of per-agent limit used */
  usagePercent: number;
}

export type BudgetStatus = "within_budget" | "approaching_limit" | "at_limit" | "exceeded";

export const DEFAULT_BUDGET: UsageBudget = {
  dailyTokenLimit: 10_000_000,
  perAgentTokenLimit: 2_000_000,
  maxConcurrentAgents: 10,
  maxTaskDurationMinutes: 120,
  enforceHardLimits: false,
};
