/** * MITHOME-113 (design D8): the single template for validating the English * translation of a legal page. Used both by the admin "Validation prompt" * panel (src/components/admin/LegalValidationPrompt.tsx) and by the * project's own multi-model validation, so the two are comparable. * * WHY in code, not in the CMS: the review criteria are a quality rule, not * page content — changes must go through git review so they cannot be * weakened by accident. * WHY English: the most stable instruction language across models; the * document texts stay in their original languages. */ export type LegalSection = { id?: string | null; title?: string | null; content?: string | null } export type LegalText = { title?: string | null; lastUpdated?: string | null; sections?: LegalSection[] | null } const MISSING = '(missing — report as high severity)' const INSTRUCTIONS = `You are reviewing the English translation of a Hungarian legal document published on the website of mozdIT Bt., a Hungarian IT hosting provider. The Hungarian text is authoritative. Check every section for: 1. Meaning equivalence — nothing added, omitted or changed: same scope, conditions, numbers, deadlines and retention periods. 2. Data-protection terminology consistent with the official English text of the GDPR (e.g. controller, processor, data subject, legal basis, legitimate interest, erasure, restriction of processing) and correct English names of Hungarian authorities and laws. 3. Strength of obligations and rights — "shall", "must", "may", "is entitled to" must match the Hungarian. 4. Preserved placeholders, e-mail addresses, URLs and formatting markers (**bold**, "•" bullets, line breaks). 5. Clarity for an English-speaking reader without changing the legal meaning. Output format: - A table with the columns: Section | Severity (high / medium / low) | Issue | Hungarian excerpt | Suggested English wording. High = changes a legal meaning, right or obligation; medium = terminology or ambiguity; low = style. - Then a final verdict — APPROVE, APPROVE WITH CHANGES or REJECT — with a one-sentence justification. Do not rewrite the whole document. Note that this review is not legal advice.` const hasText = (value?: string | null) => Boolean(value?.trim()) export function hasEnglishContent(en: LegalText): boolean { return hasText(en.title) || (en.sections ?? []).some((s) => hasText(s.title) || hasText(s.content)) } function block(label: string, title?: string | null, content?: string | null) { return `[${label}] ${hasText(title) ? title : MISSING}\n${hasText(content) ? content : MISSING}` } /** The review prompt, or undefined when there is no English text to validate. */ export function buildLegalValidationPrompt(hu: LegalText, en: LegalText): string | undefined { if (!hasEnglishContent(en)) return undefined const enById = new Map((en.sections ?? []).map((s) => [s.id, s])) const header = [ `Document (HU): ${hu.title ?? ''}`, `Document (EN): ${hasText(en.title) ? en.title : MISSING}`, `Last updated (HU / EN): ${hu.lastUpdated ?? ''} / ${hasText(en.lastUpdated) ? en.lastUpdated : MISSING}`, ].join('\n') const sections = (hu.sections ?? []).map((section, index) => { const english = enById.get(section.id) ?? {} return [ `--- Section ${index + 1}${section.id ? ` (${section.id})` : ''} ---`, block('HU', section.title, section.content), block('EN', english.title, english.content), ].join('\n') }) return [INSTRUCTIONS, header, ...sections].join('\n\n') }