export type ProspectAssessment = { row: Record; suggestion: { fit: "likely_fit" | "unlikely_fit" | "unknown"; score?: number; reason: string; }; }; /** Validate the entire file before the first write, including optional legacy scores. */ export function parseProspectAssessments(input: unknown): ProspectAssessment[] { if (!Array.isArray(input) || !input.length || input.length > 100) throw new Error("Provide 1–100 assessments containing row and suggestion."); return input.map((entry) => { const row = entry?.row; const suggestion = entry?.suggestion; if ( !row || typeof row !== "object" || Array.isArray(row) || !suggestion || !["likely_fit", "unlikely_fit", "unknown"].includes(suggestion.fit) || typeof suggestion.reason !== "string" || !suggestion.reason.trim() || suggestion.reason.length > 2000 ) throw new Error( "Each assessment needs a profile row, fit (likely_fit|unlikely_fit|unknown), and a reason of 1–2000 characters.", ); const score = suggestion.score; if ( score !== undefined && (typeof score !== "number" || !Number.isInteger(score) || score < 0 || score > 100) ) throw new Error( "ICP relevance score must be a whole number from 0 to 100.", ); return { row, suggestion: { fit: suggestion.fit, reason: suggestion.reason.trim(), ...(score !== undefined ? { score } : {}), }, }; }); }