using System.Collections.Generic;
using System.Data;

namespace XmlForDB;

public class ParamAttributesRID
{
	protected static Dictionary<ParamAttributesInfo, string> paramAttributesLookup = new Dictionary<ParamAttributesInfo, string>(new ParamAttributesInfoComparer());

	public bool LookupHasValues()
	{
		return paramAttributesLookup.Count > 0;
	}

	public void ClearLookupValues()
	{
		paramAttributesLookup.Clear();
	}

	public void PopulateValues(DataSet ds)
	{
		if (ds == null || ds.Tables.Count <= 0)
		{
			return;
		}
		foreach (DataRow row in ds.Tables[0].Rows)
		{
			ParamAttributesInfo paramAttributesInfo = new ParamAttributesInfo();
			paramAttributesInfo.TestName = row[Constants.TESTNAME].ToString().Trim();
			paramAttributesInfo.ParamName = row[Constants.PARAMNAME].ToString().Trim();
			paramAttributesInfo.LoopConditions = row[Constants.LOOPCONDITIONS].ToString().Trim();
			if (!paramAttributesLookup.ContainsKey(paramAttributesInfo))
			{
				paramAttributesLookup.Add(paramAttributesInfo, row[Constants.PARAMATTRIBUTESRID].ToString());
			}
		}
	}

	public string GetIDFromLookup(string testName, string paramName, string loopConditions)
	{
		ParamAttributesInfo paramAttributesInfo = new ParamAttributesInfo();
		paramAttributesInfo.TestName = testName.Trim();
		paramAttributesInfo.ParamName = paramName.Trim();
		paramAttributesInfo.LoopConditions = loopConditions.Trim();
		string value = string.Empty;
		if (paramAttributesLookup.TryGetValue(paramAttributesInfo, out value))
		{
			return value;
		}
		return string.Empty;
	}
}
