/**
 * Safe narrowing of unknown event payloads into AnalyticsQualityScore.
 */
/**
 * Convert an unknown quality-score payload into AnalyticsQualityScore.
 * Returns undefined for missing, null, or malformed values.
 */
export function parseAnalyticsQualityScore(value) {
    if (!value || typeof value !== "object") {
        return undefined;
    }
    const record = value;
    // Reject NaN/Infinity — typeof NaN === "number"
    if (!Number.isFinite(record.overall) ||
        !Number.isFinite(record.relevance) ||
        !Number.isFinite(record.accuracy) ||
        !Number.isFinite(record.completeness)) {
        return undefined;
    }
    return {
        overall: record.overall,
        relevance: record.relevance,
        accuracy: record.accuracy,
        completeness: record.completeness,
        ...(typeof record.reasoning === "string"
            ? { reasoning: record.reasoning }
            : {}),
    };
}
