using BigRegister.Api.Contracts;

namespace BigRegister.Domain.Letters;

/// <summary>
/// SERVER-OWNED org-template validation (Brief v2 PRD §5): bounded margins so an
/// admin cannot break the letter geometry, and the identity fields a letter cannot
/// render without. The FE mirrors the bounds for instant feedback (config values on
/// the wire if ever needed); this is the authority.
/// </summary>
public static class OrgTemplateRules
{
  public const int MarginMinMm = 10;
  public const int MarginMaxMm = 50;

  /// Returns a rejection reason, or null when the draft is acceptable.
  public static string? RejectDraft(OrgTemplateDto draft)
  {
    if (string.IsNullOrWhiteSpace(draft.OrgName)) return "Organisatienaam is verplicht.";
    if (string.IsNullOrWhiteSpace(draft.SignatureName)) return "Naam van de ondertekenaar is verplicht.";
    var m = draft.Margins;
    var outOfBounds = new[] { m.TopMm, m.RightMm, m.BottomMm, m.LeftMm }
        .Any(v => v is < MarginMinMm or > MarginMaxMm);
    return outOfBounds
        ? $"Marges moeten tussen {MarginMinMm} en {MarginMaxMm} mm liggen."
        : null;
  }
}
