using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace QC.QSPRTreeSchemaLibrary;

[Serializable]
public class ConditionMgr
{
	[Serializable]
	private enum TokenType
	{
		OpParen,
		ClsParen,
		AndOrNot,
		And,
		Or,
		Not,
		Condition
	}

	[Serializable]
	private class TokenTypePair
	{
		private string token;

		private TokenType type;

		public string Token => token;

		public TokenType Type => type;

		public TokenTypePair(string token, TokenType type)
		{
			this.token = token;
			this.type = type;
		}
	}

	private string expression;

	private List<TokenTypePair> fullParenExpr;

	private List<BaseCondition> conditions;

	private PostConditionActions action;

	private string branchTextIndex = "";

	private string branchOnTestName = "";

	private bool enabled = true;

	private bool negateResult;

	public string Expression
	{
		get
		{
			return expression;
		}
		set
		{
			expression = value;
		}
	}

	public List<BaseCondition> Conditions
	{
		get
		{
			return conditions;
		}
		set
		{
			conditions = value;
		}
	}

	public string FullParenExpression
	{
		get
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (TokenTypePair item in fullParenExpr)
			{
				stringBuilder.Append(item.Token);
				stringBuilder.Append(" ");
			}
			return stringBuilder.ToString();
		}
	}

	public bool IsValid
	{
		get
		{
			bool result = true;
			foreach (BaseCondition condition in Conditions)
			{
				if (!condition.IsValid)
				{
					result = false;
					break;
				}
			}
			if (!Enabled)
			{
				result = false;
			}
			return result;
		}
	}

	public bool NegateResult
	{
		get
		{
			return negateResult;
		}
		set
		{
			negateResult = value;
		}
	}

	public PostConditionActions Action
	{
		get
		{
			return action;
		}
		set
		{
			action = value;
		}
	}

	[DefaultValue("")]
	public string BranchTestIndex
	{
		get
		{
			return branchTextIndex;
		}
		set
		{
			branchTextIndex = value;
		}
	}

	public string BranchOnTestName
	{
		get
		{
			return branchOnTestName;
		}
		set
		{
			branchOnTestName = value;
		}
	}

	[DefaultValue(true)]
	public bool Enabled
	{
		get
		{
			return enabled;
		}
		set
		{
			enabled = value;
		}
	}

	public ConditionMgr()
	{
		expression = "";
		fullParenExpr = new List<TokenTypePair>();
		conditions = new List<BaseCondition>();
	}

	public ConditionMgr(string expression)
	{
		this.expression = expression;
	}
}
