using Meezi.Core.Enums;

namespace Meezi.Core.Constants;

/// <summary>
/// Code-level DEFAULTS for per-plan numeric limits. These are the fallback /
/// seed values; the source of truth at runtime is the admin-editable
/// PlatformPlanDefinition (LimitsJson) read via IPlatformCatalogService.
/// Gating uses explicit tier sets, never `tier >= X`, so the appended Starter
/// tier (enum value 4) is handled correctly.
/// </summary>
public static class PlanLimits
{
    private static bool IsPaid(PlanTier t) => t is not PlanTier.Free;
    private static bool IsProPlus(PlanTier t) =>
        t is PlanTier.Pro or PlanTier.Business or PlanTier.Enterprise;
    private static bool IsBusinessPlus(PlanTier t) =>
        t is PlanTier.Business or PlanTier.Enterprise;

    public static int MaxOrdersPerDay(PlanTier tier) => tier switch
    {
        PlanTier.Free => 30,
        _ => int.MaxValue
    };

    /// <summary>Maximum tables a café may define.</summary>
    public static int MaxTables(PlanTier tier) => tier switch
    {
        PlanTier.Free => 6,
        PlanTier.Starter => 15,
        PlanTier.Pro => 40,
        _ => int.MaxValue
    };

    public static int MaxTerminals(PlanTier tier) => tier switch
    {
        PlanTier.Free => 1,
        PlanTier.Starter => 2,
        PlanTier.Pro => 3,
        _ => int.MaxValue
    };

    public static int MaxCustomers(PlanTier tier) => int.MaxValue; // CRM module gated by CanAccessCrm

    /// <summary>Monthly bundled SMS. The product direction is pay-as-you-go credits for
    /// all tiers, but until the credit-purchase system ships we keep the existing bundled
    /// quotas so paying cafés don't lose SMS. (Switch to 0 + credits in the SMS stage.)</summary>
    public static int MaxSmsPerMonth(PlanTier tier) => tier switch
    {
        PlanTier.Free => 0,
        PlanTier.Starter => 0,
        PlanTier.Pro => 50,
        PlanTier.Business => 200,
        _ => int.MaxValue
    };

    public static int MaxBranches(PlanTier tier) => tier switch
    {
        PlanTier.Free => 1,
        PlanTier.Starter => 1,
        PlanTier.Pro => 3,
        _ => int.MaxValue
    };

    /// <summary>How far back daily report snapshots may be queried (inclusive of today).</summary>
    public static int MaxReportHistoryDays(PlanTier tier) => tier switch
    {
        PlanTier.Free => 8,
        PlanTier.Starter => 30,
        PlanTier.Pro => 90,
        _ => int.MaxValue
    };

    /// <summary>AI image-to-3D generations per calendar month (UTC). Business+ only.</summary>
    public static int MaxMenuAi3dPerMonth(PlanTier tier) => IsBusinessPlus(tier) ? 100 : 0;

    /// <summary>Maximum active menu categories. Free is capped at 10; paid tiers unlimited.</summary>
    public static int MaxMenuCategories(PlanTier tier) => tier switch
    {
        PlanTier.Free => 10,
        _ => int.MaxValue
    };

    /// <summary>Menu items are unlimited on every tier (Free can fully build the menu).</summary>
    public static int MaxMenuItems(PlanTier tier) => int.MaxValue;

    /// <summary>CRM (customers, loyalty) — Pro and above.</summary>
    public static bool CanAccessCrm(PlanTier tier) => IsProPlus(tier);

    /// <summary>Statistics / analytics dashboards — Pro and above.</summary>
    public static bool CanAccessStatistics(PlanTier tier) => IsProPlus(tier);
}
