using TakeoutSaaS.Domain.Products.Enums;

namespace TakeoutSaaS.Application.App.Products;

/// <summary>
/// 加料模板映射辅助。
/// </summary>
internal static class ProductAddonTemplateMapping
{
    /// <summary>
    /// 解析状态字符串。
    /// </summary>
    public static bool TryParseStatus(string? status, out bool isEnabled)
    {
        var normalized = status?.Trim().ToLowerInvariant();
        switch (normalized)
        {
            case "enabled":
                isEnabled = true;
                return true;
            case "disabled":
                isEnabled = false;
                return true;
            default:
                isEnabled = true;
                return false;
        }
    }

    /// <summary>
    /// 状态转字符串。
    /// </summary>
    public static string ToStatusText(bool isEnabled)
    {
        return isEnabled ? "enabled" : "disabled";
    }

    /// <summary>
    /// 依据最大可选数推导选择类型。
    /// </summary>
    public static AttributeSelectionType ToSelectionType(int maxSelect)
    {
        return maxSelect <= 1 ? AttributeSelectionType.Single : AttributeSelectionType.Multiple;
    }
}
