namespace JobTrackerApi.Models;

/// <summary>
/// Compatibility catalog for the job-specific CV draft flow. These IDs predate the
/// document builder theme catalog, so they remain stable while their metadata and
/// defaults have one owner.
/// </summary>
public sealed record TailoredCvTemplate(
    string Id,
    string Title,
    string Tone,
    string AccentColor,
    string PreviewTagline,
    string PreviewSummary,
    IReadOnlyList<string> PreviewBullets,
    string RewriteGuidance);

public static class TailoredCvTemplateCatalog
{
    public static readonly IReadOnlyList<TailoredCvTemplate> Templates = new[]
    {
        new TailoredCvTemplate("ats-minimal", "ATS Minimal", "Scanner-friendly", "slate", "Compact, direct, and easy to parse.", "Best for broad application flows and recruiter scanning.", new[] { "Tight hierarchy", "Keyword-friendly", "Low visual risk" }, "ATS Minimal template: clean, compact, scanner-friendly, and easy to tailor."),
        new TailoredCvTemplate("harvard", "Harvard", "Traditional", "brick", "Formal and restrained.", "Good for conservative hiring flows or academic-adjacent applications.", new[] { "Classic serif rhythm", "Strong chronology", "Credible tone" }, "Harvard template: refined, traditional, strong hierarchy, restrained and credible."),
        new TailoredCvTemplate("auckland", "Auckland", "Modern sidebar", "emerald", "Sharper highlights with a contemporary cadence.", "Pulls key strengths into a faster visual scan.", new[] { "Sidebar details", "Compact highlights", "Modern contrast" }, "Auckland template: modern sidebar layout, crisp highlights, confident but readable."),
        new TailoredCvTemplate("edinburgh", "Edinburgh", "Editorial", "plum", "More personality without losing clarity.", "Useful when the CV should feel polished and distinctive.", new[] { "Premium spacing", "Stronger personality", "Readable density" }, "Edinburgh template: polished editorial layout with stronger visual personality and premium spacing."),
        new TailoredCvTemplate("monarch", "Monarch", "Executive", "#7c2d12", "High-contrast leadership emphasis.", "Works well for senior, strategic, or client-facing roles.", new[] { "Executive summary weight", "Premium accenting", "Decision-maker friendly" }, "Monarch template: executive, premium, high-contrast emphasis on summary and leadership signals."),
        new TailoredCvTemplate("fjord", "Fjord", "Technical", "#0f4c5c", "Calm, dense, technical layout.", "Optimized for engineering resumes with richer project and skills detail.", new[] { "Technical depth", "Dense but readable", "Practical hierarchy" }, "Fjord template: calm technical layout with clear information density and practical scanability."),
    };

    private static readonly IReadOnlyDictionary<string, string> NamedAccents =
        new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
        {
            ["slate"] = "#334155",
            ["blue"] = "#1d4ed8",
            ["emerald"] = "#047857",
            ["plum"] = "#7c3aed",
            ["brick"] = "#b45309",
        };

    public static string NormalizeId(string? value)
    {
        var normalized = (value ?? string.Empty).Trim().ToLowerInvariant();
        if (normalized is "base" or "legacy-text") return Templates[0].Id;
        return Templates.Any(template => template.Id == normalized) ? normalized : Templates[0].Id;
    }

    public static TailoredCvTemplate Resolve(string? value)
    {
        var id = NormalizeId(value);
        return Templates.First(template => template.Id == id);
    }

    public static string ResolveAccent(string? value)
    {
        var normalized = (value ?? string.Empty).Trim();
        if (NamedAccents.TryGetValue(normalized, out var accent)) return accent;
        return normalized.StartsWith('#') ? normalized : NamedAccents["slate"];
    }
}
