using System.Collections;

namespace QC.QTMScriptKernel;

public class ParameterHandler
{
	private ParameterHandler()
	{
	}

	public static void CreateParameters(object sParams, out ArrayList parameters)
	{
		parameters = new ArrayList();
		try
		{
			object[,] array = (object[,])sParams;
			if (array != null)
			{
				for (int i = 0; i < array.GetLength(0); i++)
				{
					Parameter parameter = new Parameter();
					parameter.Name = array[i, 0].ToString();
					parameter.Value = array[i, 1].ToString();
					parameter.LowerLimit = array[i, 2].ToString();
					parameter.UpperLimit = array[i, 3].ToString();
					parameter.NumberOfElements = int.Parse(array[i, 4].ToString());
					parameter.IOType = array[i, 5].ToString();
					parameter.UnitOfMeasure = array[i, 6].ToString();
					parameter.Description = array[i, 7].ToString();
					parameter.DataType = array[i, 8].ToString();
					parameters.Add(parameter);
				}
			}
		}
		catch
		{
		}
	}

	public static object GetParameterObject(ArrayList parameters)
	{
		try
		{
			object[,] array = new object[12, parameters.Count];
			int num = 0;
			foreach (Parameter parameter in parameters)
			{
				array[0, num] = parameter.Name;
				array[1, num] = parameter.DataType;
				array[2, num] = parameter.NumberOfElements;
				array[3, num] = parameter.Value;
				array[4, num] = parameter.IOType;
				array[5, num] = parameter.UpperLimit;
				array[6, num] = parameter.LowerLimit;
				array[7, num] = parameter.UnitOfMeasure;
				array[8, num] = parameter.Description;
				array[9, num] = parameter.Constraint;
				array[10, num] = parameter.DisplayHint;
				array[11, num] = true;
				num++;
			}
			return array;
		}
		catch
		{
			return null;
		}
	}

	public static void UpdateParameters(ArrayList oldParams, Hashtable newParams)
	{
		foreach (Parameter oldParam in oldParams)
		{
			if (oldParam.IOType == "Output" && newParams.ContainsKey(oldParam.Name.ToUpper()))
			{
				oldParam.Value = (string)newParams[oldParam.Name.ToUpper()];
			}
		}
	}
}
