using System;

namespace Robust.Shared.Prototypes;

public static class PrototypeUtility
{
    /// <summary>
    /// Prototypes using autogenerated names are required to end in this string.
    /// </summary>
    public const string PrototypeNameEnding = "Prototype";

    /// <summary>
    /// Given the type name of a Prototype, returns an autogenerated name for it.
    /// </summary>
    public static string CalculatePrototypeName(string type)
    {
        var name = type.AsSpan();
        if (!type.EndsWith(PrototypeNameEnding))
            return $"{char.ToLowerInvariant(name[0])}{name.Slice(1).ToString()}";

        return $"{char.ToLowerInvariant(name[0])}{name.Slice(1, name.Length - PrototypeNameEnding.Length - 1).ToString()}";
    }
}
