import type { ProofInput, ProofValidation } from '../_types.js'; const WEB_HOSTS = ['vercel.app', 'onrender.com', 'netlify.app']; const NOTEBOOK_HOSTS = ['colab.research.google.com', 'kaggle.com']; const DESIGN_HOSTS = ['behance.net', 'dribbble.com', 'adobe.com']; function hasKnownHost(url: string, hosts: string[]): boolean { try { const host = new URL(url).hostname.toLowerCase(); return hosts.some((candidate) => host.endsWith(candidate)); } catch { return false; } } export function validateProof(input: ProofInput): ProofValidation { const provided: string[] = []; const missing: string[] = []; if (input.liveDemoUrl) { provided.push('liveDemoUrl'); } if (input.notebookUrl) { provided.push('notebookUrl'); } if (input.portfolioUrl) { provided.push('portfolioUrl'); } if (input.projectType === 'design') { const ok = !!input.portfolioUrl && hasKnownHost(input.portfolioUrl, DESIGN_HOSTS); if (!ok) { missing.push('Valid design portfolio URL (Behance/Dribbble)'); } return { passed: ok, requiredProof: 'Design portfolio link', providedProof: provided, missing, }; } if (input.projectType === 'web') { const ok = !!input.liveDemoUrl && hasKnownHost(input.liveDemoUrl, WEB_HOSTS); if (!ok) { missing.push('Valid web deployment URL (Vercel/Render/Netlify)'); } return { passed: ok, requiredProof: 'Web deployment link', providedProof: provided, missing, }; } const notebookOk = !!input.notebookUrl && hasKnownHost(input.notebookUrl, NOTEBOOK_HOSTS); if (!notebookOk) { missing.push('Valid Colab/Kaggle demo link'); } return { passed: notebookOk, requiredProof: 'Notebook/demo proof link', providedProof: provided, missing, }; }