/**
 * SpendRecord type and SpendEmitter
 *
 * Foundation for multi-model spend tracking. SpendRecord captures per-request
 * cost data across all LLM providers. SpendEmitter is a singleton EventEmitter
 * that decouples tracking from persistence and alerting.
 */
import { EventEmitter } from 'events';
import { randomUUID } from 'crypto';
/**
 * Create a SpendRecord with generated ID and timestamp
 */
export function createSpendRecord(input) {
    return {
        id: randomUUID(),
        timestamp: new Date().toISOString(),
        provider: input.provider,
        model: input.model,
        input_tokens: input.input_tokens,
        output_tokens: input.output_tokens,
        cached_tokens: input.cached_tokens ?? 0,
        cache_write_tokens: input.cache_write_tokens ?? 0,
        reasoning_tokens: input.reasoning_tokens ?? 0,
        cost_usd: input.cost_usd,
        cost_source: input.cost_source,
        project: input.project,
        increment_id: input.increment_id,
        session_id: input.session_id,
        duration_ms: input.duration_ms,
    };
}
/**
 * Singleton EventEmitter for spend tracking events.
 * Decouples spend record creation from persistence and alerting.
 */
export class SpendEmitter extends EventEmitter {
    constructor() {
        super();
        this.setMaxListeners(20);
    }
    static getInstance() {
        if (!SpendEmitter.instance) {
            SpendEmitter.instance = new SpendEmitter();
        }
        return SpendEmitter.instance;
    }
    /** Type-safe emit for spend events */
    emitSpend(record) {
        return this.emit('spend', record);
    }
    /** Type-safe listener registration */
    onSpend(listener) {
        return this.on('spend', listener);
    }
    /** Type-safe listener removal */
    offSpend(listener) {
        return this.off('spend', listener);
    }
}
//# sourceMappingURL=spend-record.js.map