using System;
using System.Data;
using System.Reflection;
using System.Windows.Forms;
using QC.QTMDotNetKernelInterface;

namespace QC.QTMDotNetKernel.Registry;

public class TestParameter : MarshalByRefObject
{
	private string name = "";

	private string displayName = "";

	private string pValue = "";

	private DataTable pDataTable = new DataTable("Default");

	private string dataType = "";

	private string iOType = "Input";

	private string description = "";

	private string upperLimit = "";

	private string lowerLimit = "";

	private string unitOfMeasure = "";

	private string constraints = "";

	private DisplayHints displayHint;

	private int numberOfElements = 1;

	private int position = -1;

	private bool hasAttributes;

	private bool argument;

	private bool returnValue;

	private bool isSingle;

	private bool is64Bit;

	private bool isUnsigned;

	private bool isRef;

	private bool isVirtual;

	private Type type;

	private CheckState checkedState;

	private bool isArray;

	private bool isNullable;

	private string parentName = "";

	private bool isEditableInTestPlan;

	public string ParentName
	{
		get
		{
			return parentName;
		}
		set
		{
			parentName = value;
		}
	}

	public bool IsNullable
	{
		get
		{
			return isNullable;
		}
		set
		{
			isNullable = value;
		}
	}

	public bool ReturnValue
	{
		get
		{
			return returnValue;
		}
		set
		{
			returnValue = value;
		}
	}

	public string Name
	{
		get
		{
			return name;
		}
		set
		{
			name = value;
		}
	}

	public string DisplayName
	{
		get
		{
			return displayName;
		}
		set
		{
			displayName = value;
		}
	}

	public string Value
	{
		get
		{
			return pValue;
		}
		set
		{
			pValue = value;
		}
	}

	public string DataType
	{
		get
		{
			return dataType;
		}
		set
		{
			switch (value)
			{
			case "Byte":
				dataType = "Byte";
				break;
			case "Byte[]":
				isArray = true;
				dataType = "Byte";
				break;
			case "Byte&":
				isRef = true;
				dataType = "Byte";
				break;
			case "Byte[]&":
				isRef = true;
				isArray = true;
				dataType = "Byte";
				break;
			case "SByte":
				dataType = "SByte";
				break;
			case "SByte[]":
				isArray = true;
				dataType = "SByte";
				break;
			case "SByte&":
				isRef = true;
				dataType = "SByte";
				break;
			case "SByte[]&":
				isRef = true;
				isArray = true;
				dataType = "SByte";
				break;
			case "Boolean":
				dataType = "Boolean";
				break;
			case "Boolean[]":
				isArray = true;
				dataType = "Boolean";
				break;
			case "Boolean&":
				isRef = true;
				dataType = "Boolean";
				break;
			case "Boolean[]&":
				isArray = true;
				isRef = true;
				dataType = "Boolean";
				break;
			case "Int16":
				isSingle = true;
				dataType = "Int16";
				break;
			case "Int16[]":
				isArray = true;
				isSingle = true;
				dataType = "Int16";
				break;
			case "Int16&":
				isSingle = true;
				isRef = true;
				dataType = "Int16";
				break;
			case "Int16[]&":
				isArray = true;
				isSingle = true;
				isRef = true;
				dataType = "Int16";
				break;
			case "Int":
			case "int":
			case "Int32":
				dataType = "Int";
				break;
			case "Int32[]":
				isArray = true;
				dataType = "Int";
				break;
			case "Int32&":
				isRef = true;
				dataType = "Int";
				break;
			case "Int32[]&":
				isArray = true;
				isRef = true;
				dataType = "Int";
				break;
			case "Int64":
				isSingle = false;
				is64Bit = true;
				dataType = "Int64";
				break;
			case "Int64[]":
				isArray = true;
				isSingle = false;
				is64Bit = true;
				dataType = "Int64";
				break;
			case "Int64&":
				isSingle = false;
				isRef = true;
				is64Bit = true;
				dataType = "Int64";
				break;
			case "Int64[]&":
				isArray = true;
				isSingle = false;
				isRef = true;
				is64Bit = true;
				dataType = "Int64";
				break;
			case "UInt16":
				isSingle = true;
				isUnsigned = true;
				dataType = "UInt16";
				break;
			case "UInt16[]":
				isArray = true;
				isSingle = true;
				isUnsigned = true;
				dataType = "UInt16";
				break;
			case "UInt16&":
				isSingle = true;
				isRef = true;
				isUnsigned = true;
				dataType = "UInt16";
				break;
			case "UInt16[]&":
				isArray = true;
				isSingle = true;
				isRef = true;
				isUnsigned = true;
				dataType = "UInt16";
				break;
			case "UInt":
			case "uint":
			case "UInt32":
				isUnsigned = true;
				dataType = "UInt32";
				break;
			case "UInt32[]":
				isArray = true;
				isUnsigned = true;
				dataType = "UInt32";
				break;
			case "UInt32&":
				isRef = true;
				isUnsigned = true;
				dataType = "UInt32";
				break;
			case "UInt32[]&":
				isArray = true;
				isRef = true;
				isUnsigned = true;
				dataType = "UInt32";
				break;
			case "UInt64":
				isSingle = false;
				is64Bit = true;
				isUnsigned = true;
				dataType = "UInt64";
				break;
			case "UInt64[]":
				isArray = true;
				isSingle = false;
				is64Bit = true;
				isUnsigned = true;
				dataType = "UInt64";
				break;
			case "UInt64&":
				isSingle = false;
				isRef = true;
				is64Bit = true;
				isUnsigned = true;
				dataType = "UInt64";
				break;
			case "UInt64[]&":
				isArray = true;
				isSingle = false;
				isRef = true;
				is64Bit = true;
				isUnsigned = true;
				dataType = "UInt64";
				break;
			case "Single":
				isSingle = true;
				dataType = "Single";
				break;
			case "Single[]":
				isArray = true;
				isSingle = true;
				dataType = "Single";
				break;
			case "Single&":
				isRef = true;
				isSingle = true;
				dataType = "Single";
				break;
			case "Single[]&":
				isArray = true;
				isRef = true;
				isSingle = true;
				dataType = "Single";
				break;
			case "Decimal":
				dataType = "Decimal";
				break;
			case "Decimal[]":
				isArray = true;
				dataType = "Decimal";
				break;
			case "Decimal&":
				isRef = true;
				dataType = "Decimal";
				break;
			case "Decimal[]&":
				isArray = true;
				isRef = true;
				dataType = "Decimal";
				break;
			case "double":
			case "Double":
				dataType = "Double";
				break;
			case "Double[]":
				isArray = true;
				dataType = "Double";
				break;
			case "Double&":
				isRef = true;
				dataType = "Double";
				break;
			case "Double[]&":
				isArray = true;
				isRef = true;
				dataType = "Double";
				break;
			case "String":
				dataType = "String";
				break;
			case "String[]":
				isArray = true;
				dataType = "String";
				break;
			case "String&":
				isRef = true;
				dataType = "String";
				break;
			case "String[]&":
				isArray = true;
				isRef = true;
				dataType = "String";
				break;
			case "Char":
				dataType = "Char";
				break;
			case "Char[]":
				isArray = true;
				dataType = "Char";
				break;
			case "Char&":
				isRef = true;
				dataType = "Char";
				break;
			case "Char[]&":
				isArray = true;
				isRef = true;
				dataType = "Char";
				break;
			case "DataTable":
				dataType = "DataTable";
				break;
			default:
				dataType = value;
				break;
			}
		}
	}

	public string IOType
	{
		get
		{
			return iOType;
		}
		set
		{
			iOType = value;
		}
	}

	public string Description
	{
		get
		{
			return description;
		}
		set
		{
			description = value;
		}
	}

	public string UpperLimit
	{
		get
		{
			return upperLimit;
		}
		set
		{
			upperLimit = value;
		}
	}

	public string LowerLimit
	{
		get
		{
			return lowerLimit;
		}
		set
		{
			lowerLimit = value;
		}
	}

	public string UnitOfMeasure
	{
		get
		{
			return unitOfMeasure;
		}
		set
		{
			unitOfMeasure = value;
		}
	}

	public string Constraints
	{
		get
		{
			return constraints;
		}
		set
		{
			constraints = value;
		}
	}

	public DisplayHints DisplayHint
	{
		get
		{
			return displayHint;
		}
		set
		{
			displayHint = value;
		}
	}

	public int NumberOfElements
	{
		get
		{
			return numberOfElements;
		}
		set
		{
			numberOfElements = value;
		}
	}

	public int Position
	{
		get
		{
			return position;
		}
		set
		{
			position = value;
		}
	}

	public CheckState CheckedState
	{
		get
		{
			return checkedState;
		}
		set
		{
			checkedState = value;
		}
	}

	public bool HasAttributes
	{
		get
		{
			return hasAttributes;
		}
		set
		{
			hasAttributes = value;
		}
	}

	public bool Argument
	{
		get
		{
			return argument;
		}
		set
		{
			argument = value;
		}
	}

	public bool IsSingle
	{
		get
		{
			return isSingle;
		}
		set
		{
			isSingle = value;
		}
	}

	public bool IsRef
	{
		get
		{
			return isRef;
		}
		set
		{
			isRef = value;
		}
	}

	public bool IsVirtual
	{
		get
		{
			return isVirtual;
		}
		set
		{
			isVirtual = value;
		}
	}

	public bool Is64Bit
	{
		get
		{
			return is64Bit;
		}
		set
		{
			is64Bit = value;
		}
	}

	public bool IsUnsigned
	{
		get
		{
			return isUnsigned;
		}
		set
		{
			isUnsigned = value;
		}
	}

	public Type Type
	{
		get
		{
			return type;
		}
		set
		{
			this.type = value;
			if (value.Name.EndsWith("[]&") || value.IsArray)
			{
				string text;
				if (value.Name.EndsWith("[]&"))
				{
					isRef = true;
					text = value.FullName.Replace("[]&", "");
				}
				else
				{
					text = value.FullName.Replace("[]", "");
				}
				Type type = value.Assembly.GetType(text);
				if (type.IsEnum)
				{
					this.type = type;
					IsArray = true;
				}
			}
			if (this.type.IsEnum)
			{
				Array values = Enum.GetValues(this.type);
				string[] names = Enum.GetNames(this.type);
				int[] array = new int[values.Length];
				for (int i = 0; i < values.Length; i++)
				{
					array[i] = (int)values.GetValue(i);
				}
				string text2 = "";
				for (int j = 0; j < names.Length; j++)
				{
					if (j == 0)
					{
						text2 = names[j] + "=" + array[j];
						continue;
					}
					object obj = text2;
					text2 = string.Concat(obj, ";", names[j], "=", array[j]);
				}
				DisplayHint = DisplayHints.ENUM_LIST;
				Constraints = text2;
				DataType = "Int";
			}
			else if ((this.type.IsGenericType && this.type.GetGenericTypeDefinition() == typeof(Nullable<>)) || this.type.FullName.Contains("System.Nullable"))
			{
				HandleNullableDataTypes();
			}
			else
			{
				DataType = value.Name;
			}
		}
	}

	public bool IsArray
	{
		get
		{
			return isArray;
		}
		set
		{
			isArray = value;
		}
	}

	public bool IsDataTable => DataType == "DataTable";

	public DataTable DataTableValue
	{
		get
		{
			return pDataTable;
		}
		set
		{
			pDataTable = value;
		}
	}

	public bool IsEditableInTestPlan
	{
		get
		{
			return isEditableInTestPlan;
		}
		set
		{
			isEditableInTestPlan = value;
		}
	}

	public bool CanEditResultValue { get; set; }

	private void HandleNullableDataTypes()
	{
		try
		{
			PropertyInfo property = type.GetProperty("Value");
			DataType = property.PropertyType.Name.ToString();
			IsNullable = true;
		}
		catch
		{
			if (type.FullName.Contains("System.Nullable"))
			{
				IsNullable = true;
				if (type.FullName.Contains("System.Double"))
				{
					DataType = "Double";
					return;
				}
				if (type.FullName.Contains("Int32"))
				{
					DataType = "Int";
					return;
				}
				if (type.FullName.Contains("Int16"))
				{
					DataType = "Int16";
					return;
				}
				if (type.FullName.Contains("Int64"))
				{
					DataType = "Int64";
					return;
				}
				if (type.FullName.Contains("Int"))
				{
					DataType = "Int";
					return;
				}
				if (type.FullName.Contains("System.UInt32"))
				{
					DataType = "UInt32";
					return;
				}
				if (type.FullName.Contains("System.UInt16"))
				{
					DataType = "UInt16";
					return;
				}
				if (type.FullName.Contains("System.UInt64"))
				{
					DataType = "UInt64";
					return;
				}
				if (type.FullName.Contains("System.Single"))
				{
					DataType = "Single";
					return;
				}
				if (type.FullName.Contains("System.Boolean"))
				{
					DataType = "Boolean";
					return;
				}
				if (type.FullName.Contains("System.Decimal"))
				{
					DataType = "Decimal";
					return;
				}
				if (type.FullName.Contains("System.Long"))
				{
					DataType = "Long";
					return;
				}
				if (type.FullName.Contains("System.Char"))
				{
					DataType = "Char";
					return;
				}
				if (type.FullName.Contains("System.Byte"))
				{
					DataType = "Byte";
					return;
				}
				if (type.FullName.Contains("System.SByte"))
				{
					DataType = "SByte";
					return;
				}
				IsNullable = false;
				DataType = "System.String";
			}
		}
	}

	public TestParameter()
	{
	}

	public TestParameter(string name)
	{
		this.name = name;
		if (pDataTable != null)
		{
			pDataTable.TableName = name;
			DataColumn column = new DataColumn("def")
			{
				DefaultValue = true
			};
			pDataTable.Columns.Add(column);
		}
	}

	public TestParameter Clone()
	{
		TestParameter testParameter = new TestParameter(Name);
		testParameter.Value = Value;
		testParameter.DataTableValue = DataTableValue;
		testParameter.Constraints = Constraints;
		testParameter.DisplayHint = DisplayHint;
		testParameter.Type = Type;
		testParameter.Description = Description;
		testParameter.IOType = IOType;
		testParameter.LowerLimit = LowerLimit;
		testParameter.NumberOfElements = NumberOfElements;
		testParameter.Position = Position;
		testParameter.UnitOfMeasure = UnitOfMeasure;
		testParameter.UpperLimit = UpperLimit;
		testParameter.HasAttributes = HasAttributes;
		testParameter.IsRef = IsRef;
		testParameter.IsSingle = IsSingle;
		testParameter.Argument = Argument;
		testParameter.CheckedState = CheckedState;
		testParameter.IsVirtual = IsVirtual;
		testParameter.IsArray = IsArray;
		testParameter.IsUnsigned = IsUnsigned;
		testParameter.Is64Bit = Is64Bit;
		testParameter.IsNullable = IsNullable;
		testParameter.ParentName = ParentName;
		testParameter.DisplayName = DisplayName;
		testParameter.IsEditableInTestPlan = IsEditableInTestPlan;
		testParameter.CanEditResultValue = CanEditResultValue;
		return testParameter;
	}

	public void Reset()
	{
		try
		{
			if (!HasAttributes && !Argument)
			{
				CheckedState = CheckState.Unchecked;
			}
			else
			{
				CheckedState = CheckState.Checked;
			}
		}
		catch
		{
		}
	}

	public void Clear()
	{
		try
		{
			if (!Argument)
			{
				CheckedState = CheckState.Unchecked;
			}
			else
			{
				CheckedState = CheckState.Checked;
			}
		}
		catch
		{
		}
	}
}
