namespace BigRegister.Domain.Diplomas;

/// <summary>
/// SERVER-OWNED business rules for diplomas. This is the single place a policy
/// changes: which profession a study program maps to, and which policy questions
/// (geldigheidsvragen) apply to a diploma. The frontend renders these; it never
/// derives them.
/// </summary>
public static class DiplomaRules
{
    // RULE: study program → BIG profession.
    private static readonly Dictionary<string, string> ProfessionByProgram = new(StringComparer.OrdinalIgnoreCase)
    {
        ["geneeskunde"] = "Arts",
        ["verpleegkunde"] = "Verpleegkundige",
        ["fysiotherapie"] = "Fysiotherapeut",
        ["farmacie"] = "Apotheker",
        ["tandheelkunde"] = "Tandarts",
    };

    public static string ProfessionFor(Diploma d) =>
        ProfessionByProgram.TryGetValue(d.Opleiding, out var beroep) ? beroep : "Onbekend";

    /// <summary>Professions a user may declare for a manual (unlisted) diploma.</summary>
    public static IReadOnlyList<string> ManualProfessions() =>
        ProfessionByProgram.Values.Distinct().ToList();

    // --- Policy questions (geldigheidsvragen) ---

    private static readonly PolicyQuestion NlTaalEngelstalig = new(
        "nl-taalvaardigheid",
        "Uw opleiding was Engelstalig. Beheerst u de Nederlandse taal op het vereiste niveau (B2)?",
        QuestionType.JaNee);

    private static readonly PolicyQuestion NlTaalManual = new(
        "nl-taalvaardigheid",
        "Beheerst u de Nederlandse taal op het vereiste niveau (B2)?",
        QuestionType.JaNee);

    private static readonly PolicyQuestion DiplomaErkend = new(
        "diploma-erkend",
        "Is uw diploma erkend door de Nederlandse overheid (bijv. via Nuffic)?",
        QuestionType.JaNee);

    private static readonly PolicyQuestion Toelichting = new(
        "toelichting",
        "Geef een korte toelichting op uw diploma en opleiding.",
        QuestionType.Tekst);

    /// <summary>
    /// RULE: an English-language diploma requires proof of Dutch proficiency (B2).
    /// Add a question here to apply it to a (set of) diploma(s) — a single backend
    /// change, no frontend change.
    /// </summary>
    public static IReadOnlyList<PolicyQuestion> QuestionsFor(Diploma d)
    {
        var questions = new List<PolicyQuestion>();
        if (d.Engelstalig)
            questions.Add(NlTaalEngelstalig);
        return questions;
    }

    /// <summary>
    /// RULE: a manual diploma is unverified, so the strictest (maximal) set applies.
    /// </summary>
    public static IReadOnlyList<PolicyQuestion> ManualQuestions() =>
        new[] { NlTaalManual, DiplomaErkend, Toelichting };
}
