// engine/llm-providers/cost-tracker.ts — Cost tracking per provider.
// SPEC-083 AC-13
/** In-memory cost records (would be persisted to llm-costs.json in production). */
const costRecords = [];
/**
 * Record a cost event for a provider recommendation.
 */
export function recordCost(providerId, modelId, tokensEstimated, costEstimated) {
    const record = {
        providerId,
        modelId,
        tokensEstimated,
        costEstimated,
        timestamp: new Date().toISOString(),
    };
    costRecords.push(record);
    return record;
}
/**
 * Get cost summary for a specific provider with daily/weekly/monthly aggregation.
 */
export function getCostSummary(providerId) {
    const now = Date.now();
    const dayMs = 24 * 60 * 60 * 1000;
    const providerRecords = costRecords.filter((r) => r.providerId === providerId);
    let daily = 0;
    let weekly = 0;
    let monthly = 0;
    for (const record of providerRecords) {
        const age = now - new Date(record.timestamp).getTime();
        /* v8 ignore next 9 -- time-based branches: all records in tests are recent */
        if (age <= dayMs) {
            daily += record.costEstimated;
        }
        if (age <= 7 * dayMs) {
            weekly += record.costEstimated;
        }
        if (age <= 30 * dayMs) {
            monthly += record.costEstimated;
        }
    }
    return {
        providerId,
        daily: Math.round(daily * 10000) / 10000,
        weekly: Math.round(weekly * 10000) / 10000,
        monthly: Math.round(monthly * 10000) / 10000,
        requestCount: providerRecords.length,
    };
}
/**
 * Get cost summaries for all providers that have records.
 */
export function getAllCostSummaries() {
    const providerIds = [...new Set(costRecords.map((r) => r.providerId))];
    return providerIds.map((id) => getCostSummary(id));
}
/**
 * Get all raw cost records (for persistence/export).
 */
export function getCostRecords() {
    return [...costRecords];
}
/**
 * Load cost records from persisted data.
 */
export function loadCostRecords(records) {
    costRecords.length = 0;
    costRecords.push(...records);
}
/**
 * Clear all cost records (for testing).
 */
export function clearCostRecords() {
    costRecords.length = 0;
}
//# sourceMappingURL=cost-tracker.js.map