using Meezi.Core.Constants;
using Meezi.Core.Enums;

namespace Meezi.Core.Platform;

/// <summary>
/// Serializable per-plan numeric limits, stored as PlatformPlanDefinition.LimitsJson
/// and editable by admins. Missing fields default to "unlimited" (or 0 for opt-in
/// quotas) so older stored JSON stays safe. Defaults come from <see cref="PlanLimits"/>.
/// </summary>
public class PlanLimitsData
{
    public int MaxOrdersPerDay { get; set; } = int.MaxValue;
    public int MaxTables { get; set; } = int.MaxValue;
    public int MaxTerminals { get; set; } = int.MaxValue;
    public int MaxCustomers { get; set; } = int.MaxValue;
    public int MaxSmsPerMonth { get; set; } = 0;
    public int MaxBranches { get; set; } = int.MaxValue;
    public int MaxReportHistoryDays { get; set; } = int.MaxValue;
    public int MaxMenuCategories { get; set; } = int.MaxValue;
    public int MaxMenuItems { get; set; } = int.MaxValue;
    public int MaxMenuAi3dPerMonth { get; set; } = 0;

    public static PlanLimitsData ForTier(PlanTier tier) => new()
    {
        MaxOrdersPerDay = PlanLimits.MaxOrdersPerDay(tier),
        MaxTables = PlanLimits.MaxTables(tier),
        MaxTerminals = PlanLimits.MaxTerminals(tier),
        MaxCustomers = PlanLimits.MaxCustomers(tier),
        MaxSmsPerMonth = PlanLimits.MaxSmsPerMonth(tier),
        MaxBranches = PlanLimits.MaxBranches(tier),
        MaxReportHistoryDays = PlanLimits.MaxReportHistoryDays(tier),
        MaxMenuCategories = PlanLimits.MaxMenuCategories(tier),
        MaxMenuItems = PlanLimits.MaxMenuItems(tier),
        MaxMenuAi3dPerMonth = PlanLimits.MaxMenuAi3dPerMonth(tier),
    };
}
