import { DuoLookupDto } from '@registratie/contracts/duo-diplomas.dto'; import { RegistratieMsg } from '@registratie/domain/registratie-wizard.machine'; import { HANDMATIG } from './beroep.step'; /** * Resolve the diploma that the user picked into the machine message it implies. * * The DUO payload maps a diploma id onto a server-derived beroep and the policy * questions that apply to it. Reading that map is message construction, so it * belongs beside the container, not in the beroep step. The backend stays the * authority on both values (ADR-0001) — this function only selects them. * * Returns null when the id matches no known diploma. The caller then dispatches * nothing and the wizard keeps its current state. */ export function diplomaMsg(data: DuoLookupDto, id: string): RegistratieMsg | null { if (id === HANDMATIG) { return { tag: 'KiesHandmatig', vraagIds: data.handmatig.policyQuestions.map((q) => q.id) }; } const diploma = data.diplomas.find((d) => d.id === id); if (!diploma) return null; return { tag: 'KiesDiploma', diplomaId: diploma.id, beroep: diploma.beroep, vraagIds: diploma.policyQuestions.map((q) => q.id), }; }