using System;
using System.Collections.Generic;

namespace QC.MMI.MMI_Common;

public class INI_FileStructure
{
	public string sectionName;

	public NameValue[] nameValueList;

	public NameValue[] parameterList;

	public void AddNameValuePair(string name, string value)
	{
		NameValue nameValue = new NameValue(name, value);
		if (nameValueList == null)
		{
			nameValueList = new NameValue[1];
			nameValueList[0] = nameValue;
		}
		else
		{
			Array.Resize(ref nameValueList, nameValueList.Length + 1);
			nameValueList[nameValueList.Length - 1] = nameValue;
		}
	}

	public void AddParameterPair(string name, string value)
	{
		NameValue nameValue = new NameValue(name, value);
		if (parameterList == null)
		{
			parameterList = new NameValue[1];
			parameterList[0] = nameValue;
		}
		else
		{
			Array.Resize(ref parameterList, parameterList.Length + 1);
			parameterList[parameterList.Length - 1] = nameValue;
		}
	}

	public string GetTestName()
	{
		string result = "";
		for (int i = 0; i < nameValueList.Length; i++)
		{
			if (nameValueList[i].name == "TEST_NAME")
			{
				return result = nameValueList[i].value.ToUpper();
			}
		}
		return result;
	}

	public string GetResult()
	{
		string result = "";
		for (int i = 0; i < nameValueList.Length; i++)
		{
			if (nameValueList[i].name == "Result")
			{
				return result = nameValueList[i].value.ToUpper();
			}
		}
		return result;
	}

	public int GetNumOfParam()
	{
		if (parameterList != null)
		{
			return parameterList.Length;
		}
		return 0;
	}

	public void GenerateParamList()
	{
		List<NameValue> list = new List<NameValue>();
		for (int i = 0; i < nameValueList.Length; i++)
		{
			if (nameValueList[i].name != "TEST_NAME" && nameValueList[i].name != "Result")
			{
				NameValue item = new NameValue(nameValueList[i].name, nameValueList[i].value);
				list.Add(item);
			}
		}
		parameterList = list.ToArray();
	}

	public NameValue GetParam(int index)
	{
		return parameterList[index];
	}
}
