using System.Text.RegularExpressions; namespace BigRegister.Domain.Submissions; /// /// SERVER-OWNED submit rules (ported from the frontend submit-*.ts commands, where /// they were hardcoded). Each method returns a rejection reason, or null when the /// submission is accepted. The reference is generated server-side on acceptance. /// public static class SubmissionRules { // RULE: an application reporting zero worked hours is rejected. public static string? RejectZeroUren(int uren) => uren == 0 ? "Aanvraag afgewezen: geen gewerkte uren geregistreerd." : null; private static readonly Regex PhonePattern = new(@"^0\d{9}$", RegexOptions.Compiled); private static readonly Regex StrippedChars = new(@"[\s\-()]", RegexOptions.Compiled); private static readonly Regex LeadingCountryCode = new(@"^\+31", RegexOptions.Compiled); // RULE: a contact change needs a well-formed Dutch phone number (10 digits, leading // 0, formatting stripped). The BRP address is authoritative and cannot be changed // here (WP-34), so only the phone is submitted. The server re-validates format // authoritatively (the FE check is UX-only) — and must strip the SAME formatting the // FE's parseTelefoonnummer does (whitespace/dashes/parens, a leading +31 → 0; WP-75), // or the two sides disagree on what's a valid number. public static string? RejectPhoneChange(string telefoon) { var stripped = StrippedChars.Replace((telefoon ?? "").Trim(), ""); var digits = LeadingCountryCode.Replace(stripped, "0"); if (!PhonePattern.IsMatch(digits)) return "Voer een geldig telefoonnummer in, bijv. 0612345678."; return null; } public static string NewReference() => // ponytail: random reference is fine for a demo; a real system reserves it transactionally. "BIG-2026-" + Random.Shared.Next(100_000, 1_000_000); }