/**
 * Collector Helpers
 * Phase 9: Helper functions for collector contract compliance
 */
/**
 * Convert old-style collector result to new contract
 * Temporary migration helper
 */
export function toNewCollectorResult(oldResult, determineStatus) {
    const now = Date.now();
    // Determine status
    let status;
    if (determineStatus) {
        status = determineStatus(oldResult);
    }
    else if (!oldResult.ok) {
        status = 'UNAVAILABLE';
    }
    else {
        // Check if stale
        const age = now - oldResult.ts;
        if (age > oldResult.staleAfterMs) {
            status = 'STALE';
        }
        else {
            status = 'LIVE';
        }
    }
    // Build new result
    const result = {
        status,
        asOf: oldResult.ts,
        source: oldResult.source,
        staleAfterMs: oldResult.staleAfterMs,
    };
    // Add data for LIVE/STALE
    if (status === 'LIVE' || status === 'STALE') {
        result.data = oldResult.data;
    }
    // Add reasonCode/message/action for UNAVAILABLE/DISABLED
    if (status === 'UNAVAILABLE' || status === 'DISABLED') {
        if (oldResult.error) {
            result.reasonCode = oldResult.error.code;
            result.message = oldResult.error.message;
        }
    }
    return result;
}
//# sourceMappingURL=helpers.js.map