/**
 * Budget Service
 *
 * Tracks API usage, costs, and enforces budget limits for agents.
 *
 * @module services/autonomous/budget.service
 */
import { EventEmitter } from 'events';
import { UsageRecord, UsageSummary, BudgetConfig, BudgetStatus, BudgetAlert, BudgetReport, ReportParams, BudgetPeriod } from '../../types/budget.types.js';
/**
 * Interface for the Budget Service
 */
export interface IBudgetService {
    /**
     * Initialize the budget service
     */
    initialize(): Promise<void>;
    /**
     * Record API usage
     *
     * @param record - Usage record to store
     */
    recordUsage(record: UsageRecord): Promise<void>;
    /**
     * Get usage summary for an agent
     *
     * @param agentId - Agent identifier
     * @param period - Time period
     * @returns Usage summary
     */
    getUsage(agentId: string, period: BudgetPeriod): Promise<UsageSummary>;
    /**
     * Get usage summary for a project
     *
     * @param projectPath - Project path
     * @param period - Time period
     * @returns Usage summary
     */
    getProjectUsage(projectPath: string, period: BudgetPeriod): Promise<UsageSummary>;
    /**
     * Set budget configuration
     *
     * @param config - Budget configuration
     */
    setBudget(config: BudgetConfig): Promise<void>;
    /**
     * Get budget configuration for a scope
     *
     * @param scope - Scope identifier
     * @returns Budget configuration
     */
    getBudget(scope: string): Promise<BudgetConfig>;
    /**
     * Check budget status for an agent
     *
     * @param agentId - Agent identifier
     * @returns Budget status
     */
    checkBudget(agentId: string): Promise<BudgetStatus>;
    /**
     * Check if agent is within budget
     *
     * @param agentId - Agent identifier
     * @returns True if within budget
     */
    isWithinBudget(agentId: string): Promise<boolean>;
    /**
     * Get remaining budget for an agent
     *
     * @param agentId - Agent identifier
     * @returns Remaining budget in USD
     */
    getRemainingBudget(agentId: string): Promise<number>;
    /**
     * Register handler for budget warning events
     *
     * @param handler - Event handler
     */
    onBudgetWarning(handler: (alert: BudgetAlert) => void): void;
    /**
     * Register handler for budget exceeded events
     *
     * @param handler - Event handler
     */
    onBudgetExceeded(handler: (alert: BudgetAlert) => void): void;
    /**
     * Generate a budget report
     *
     * @param params - Report parameters
     * @returns Budget report
     */
    generateReport(params: ReportParams): Promise<BudgetReport>;
}
/**
 * Service for tracking API usage and enforcing budget limits
 *
 * @example
 * ```typescript
 * const service = BudgetService.getInstance();
 * await service.initialize();
 *
 * // Record usage after API call
 * await service.recordUsage({
 *   agentId: 'agent-001',
 *   sessionName: 'dev-session',
 *   projectPath: '/project',
 *   timestamp: new Date().toISOString(),
 *   inputTokens: 1000,
 *   outputTokens: 500,
 *   model: 'claude-3-sonnet',
 *   operation: 'task',
 * });
 *
 * // Check if agent is within budget
 * if (await service.isWithinBudget('agent-001')) {
 *   // Continue operations
 * }
 * ```
 */
export declare class BudgetService extends EventEmitter implements IBudgetService {
    private static instance;
    private readonly logger;
    private readonly usagePath;
    private readonly configPath;
    /** Budget configurations cache */
    private budgets;
    /** Global budget config */
    private globalBudget;
    /** Whether the service is initialized */
    private initialized;
    /**
     * Private constructor for singleton pattern
     */
    private constructor();
    /**
     * Gets the singleton instance
     *
     * @returns The BudgetService instance
     */
    static getInstance(): BudgetService;
    /**
     * Clears the singleton instance (for testing)
     */
    static clearInstance(): void;
    /**
     * Get the Crewly home directory
     *
     * @returns Home directory path
     */
    private getCrewlyHome;
    /**
     * Initialize the budget service
     */
    initialize(): Promise<void>;
    /**
     * Load budget configuration from file
     */
    private loadConfig;
    /**
     * Apply loaded configuration
     *
     * @param config - Configuration file contents
     */
    private applyConfig;
    /**
     * Record API usage
     *
     * @param record - Usage record to store
     */
    recordUsage(record: UsageRecord): Promise<void>;
    /**
     * Calculate cost for a usage record
     *
     * @param record - Usage record
     * @returns Estimated cost in USD
     */
    calculateCost(record: UsageRecord): number;
    /**
     * Get the file path for a day's usage
     *
     * @param timestamp - ISO timestamp
     * @returns File path
     */
    private getDayFile;
    /**
     * Append a usage record to a file
     *
     * @param filePath - File path
     * @param record - Usage record
     */
    private appendUsage;
    /**
     * Load usage records for a time period
     *
     * @param period - Time period
     * @returns Array of usage records
     */
    private loadRecords;
    /**
     * Get date strings for a period
     *
     * @param period - Time period
     * @returns Array of date strings (YYYY-MM-DD)
     */
    private getDatesForPeriod;
    /**
     * Get usage summary for an agent
     *
     * @param agentId - Agent identifier
     * @param period - Time period
     * @returns Usage summary
     */
    getUsage(agentId: string, period: BudgetPeriod): Promise<UsageSummary>;
    /**
     * Get usage summary for a project
     *
     * @param projectPath - Project path
     * @param period - Time period
     * @returns Usage summary
     */
    getProjectUsage(projectPath: string, period: BudgetPeriod): Promise<UsageSummary>;
    /**
     * Summarize usage records
     *
     * @param records - Array of usage records
     * @returns Usage summary
     */
    private summarizeRecords;
    /**
     * Set budget configuration
     *
     * @param config - Budget configuration
     */
    setBudget(config: BudgetConfig): Promise<void>;
    /**
     * Save configuration to file
     */
    private saveConfig;
    /**
     * Get budget configuration for a scope
     *
     * @param scope - Scope identifier
     * @returns Budget configuration
     */
    getBudget(scope: string): Promise<BudgetConfig>;
    /**
     * Get the effective budget for an agent (considering hierarchy)
     *
     * @param agentId - Agent identifier
     * @returns Effective budget configuration
     */
    private getEffectiveBudget;
    /**
     * Check budget status for an agent
     *
     * @param agentId - Agent identifier
     * @returns Budget status
     */
    checkBudget(agentId: string): Promise<BudgetStatus>;
    /**
     * Estimate remaining runway based on current usage
     *
     * @param usage - Current usage summary
     * @param dailyLimit - Daily budget limit
     * @returns Human-readable runway estimate
     */
    private estimateRunway;
    /**
     * Check if agent is within budget
     *
     * @param agentId - Agent identifier
     * @returns True if within budget
     */
    isWithinBudget(agentId: string): Promise<boolean>;
    /**
     * Get remaining budget for an agent
     *
     * @param agentId - Agent identifier
     * @returns Remaining budget in USD
     */
    getRemainingBudget(agentId: string): Promise<number>;
    /**
     * Check budgets and emit alerts if thresholds are crossed
     *
     * @param agentId - Agent identifier
     */
    private checkAndAlert;
    /**
     * Register handler for budget warning events
     *
     * @param handler - Event handler
     */
    onBudgetWarning(handler: (alert: BudgetAlert) => void): void;
    /**
     * Register handler for budget exceeded events
     *
     * @param handler - Event handler
     */
    onBudgetExceeded(handler: (alert: BudgetAlert) => void): void;
    /**
     * Generate a budget report
     *
     * @param params - Report parameters
     * @returns Budget report
     */
    generateReport(params: ReportParams): Promise<BudgetReport>;
    /**
     * Clear all cached data (for testing)
     */
    clearCache(): void;
    /**
     * Get all usage records (for testing)
     *
     * @param period - Time period
     * @returns All usage records
     */
    getAllRecords(period: BudgetPeriod): Promise<UsageRecord[]>;
}
//# sourceMappingURL=budget.service.d.ts.map