namespace ZB.MOM.WW.ScadaBridge.CentralUI.ScriptAnalysis;

/// <summary>
/// Parses the parameter-definitions and return-definition JSON Schema written
/// by SchemaBuilder into a <see cref="ScriptShape"/>. Delegates to
/// <see cref="JsonSchemaShapeParser"/>, which also handles legacy flat-shape
/// rows during the transition window.
/// </summary>
public static class ScriptShapeParser
{
    /// <summary>Parses the parameter and return-type JSON schemas for a script and returns a <see cref="ScriptShape"/> describing its signature.</summary>
    /// <param name="name">The canonical script name.</param>
    /// <param name="parametersJson">The JSON Schema or legacy flat-array parameters definition, or <c>null</c> for parameterless scripts.</param>
    /// <param name="returnJson">The JSON Schema or legacy return-type definition, or <c>null</c> for void scripts.</param>
    /// <returns>A <see cref="ScriptShape"/> describing the script's parameter list and return type.</returns>
    public static ScriptShape Parse(string name, string? parametersJson, string? returnJson)
    {
        var parameters = JsonSchemaShapeParser.ParseParameters(parametersJson);
        var returnType = JsonSchemaShapeParser.ParseReturnType(returnJson);
        return new ScriptShape(name, parameters, returnType);
    }
}
