namespace PlanTempus.Application.Features.Accounts.Models;

public record PlanInfo(
    string Key,
    string Name,
    string UserRange,
    decimal? PricePerMonth,
    string BadgeText,
    string BadgeClass,
    string BadgeIcon,
    IReadOnlyList<string> Features,
    bool RequiresPayment,
    bool IsContactSales
)
{
    public bool IsFree => PricePerMonth == 0;
    public string PriceDisplay => PricePerMonth.HasValue ? $"{PricePerMonth:0}" : "Kontakt os";
}

public static class PlanCatalog
{
    private static readonly Dictionary<string, PlanInfo> Plans = new()
    {
        ["basis"] = new PlanInfo(
            Key: "basis",
            Name: "Basis",
            UserRange: "1-3 brugere",
            PricePerMonth: 0,
            BadgeText: "Gratis",
            BadgeClass: "free",
            BadgeIcon: "ph-gift",
            Features: new List<string>
            {
                "Op til 3 brugere",
                "Online booking",
                "Kalender & aftalestyring",
                "Kundekartotek",
                "SMS-påmindelser"
            },
            RequiresPayment: false,
            IsContactSales: false
        ),

        ["pro"] = new PlanInfo(
            Key: "pro",
            Name: "Pro",
            UserRange: "4-8 brugere",
            PricePerMonth: 599,
            BadgeText: "Mest populære",
            BadgeClass: "popular",
            BadgeIcon: "ph-star",
            Features: new List<string>
            {
                "Op til 8 brugere",
                "Alt fra Basis",
                "Lagerstyring",
                "Avancerede rapporter",
                "Gavekort & klippekort",
                "Prioriteret support"
            },
            RequiresPayment: true,
            IsContactSales: false
        ),

        ["enterprise"] = new PlanInfo(
            Key: "enterprise",
            Name: "Enterprise",
            UserRange: "8+ brugere",
            PricePerMonth: null,
            BadgeText: "Enterprise",
            BadgeClass: "enterprise",
            BadgeIcon: "ph-buildings",
            Features: new List<string>
            {
                "Ubegrænset antal brugere",
                "Alt fra Pro",
                "Flere lokationer",
                "Tilpasset integration",
                "Dedikeret kontaktperson",
                "SLA & uptime garanti"
            },
            RequiresPayment: false,
            IsContactSales: true
        )
    };

    public static PlanInfo GetPlan(string key)
    {
        if (Plans.TryGetValue(key.ToLowerInvariant(), out var plan))
            return plan;

        // Default to Pro if invalid key
        return Plans["pro"];
    }

    public static IEnumerable<PlanInfo> GetAllPlans() => Plans.Values;

    public static PlanInfo Basis => Plans["basis"];
    public static PlanInfo Pro => Plans["pro"];
    public static PlanInfo Enterprise => Plans["enterprise"];
}
