using System;
using System.Text;

namespace QC.QsprTestObjects.TestConditions;

[Serializable]
public class TestPostCondition : BaseCondition
{
	public override bool IsValid => base.IsValid;

	public override string ConditionString
	{
		get
		{
			StringBuilder stringBuilder = new StringBuilder();
			switch (testConditionType)
			{
			case ConditionType.GlobalVariables:
				stringBuilder.Append(base.GlobalVariableName);
				stringBuilder.Append(' ');
				BaseCondition.AppendSign(stringBuilder, base.GlobalVariableSign);
				stringBuilder.Append(' ');
				if (base.CompareToType == CompareType.Constant)
				{
					stringBuilder.Append(base.GlobalVariableValue);
				}
				else if (base.CompareToType == CompareType.GlobalVariable)
				{
					stringBuilder.Append(base.GVToCompareName);
				}
				break;
			case ConditionType.TestParameters:
				stringBuilder.Append(base.ParameterName);
				if (parameterIndex != -3)
				{
					stringBuilder.Append('[');
					switch (parameterIndex)
					{
					case -2:
						stringBuilder.Append("any");
						break;
					case -1:
						stringBuilder.Append("all");
						break;
					default:
						stringBuilder.Append(parameterIndex);
						break;
					}
					stringBuilder.Append(']');
				}
				stringBuilder.Append(' ');
				BaseCondition.AppendSign(stringBuilder, base.ParameterSign);
				stringBuilder.Append(' ');
				switch (base.CompareToType)
				{
				case CompareType.Constant:
					stringBuilder.Append(base.ParameterValue);
					break;
				case CompareType.GlobalVariable:
					stringBuilder.Append(base.GVToCompareName);
					break;
				case CompareType.LowerLimit:
					stringBuilder.Append("Param LL");
					break;
				case CompareType.UpperLimit:
					stringBuilder.Append("Param UL");
					break;
				}
				break;
			case ConditionType.TestResult:
				stringBuilder.Append("Result of this test is ");
				stringBuilder.Append(base.Result.ToString());
				break;
			}
			return stringBuilder.ToString();
		}
	}

	public BaseCondition Base => base.Copy(new BaseCondition());

	public override BaseCondition Clone()
	{
		TestPostCondition bCondition = new TestPostCondition();
		base.Copy(bCondition);
		return bCondition;
	}

	public override BaseCondition Copy(BaseCondition bCondition)
	{
		return base.Copy(bCondition);
	}

	public override bool Equals(object obj)
	{
		if (obj is TestPostCondition)
		{
			return base.Equals(obj);
		}
		return false;
	}
}
