using System.Globalization;
using System.Windows.Controls;
using QC.QsprTestObjects.Parameters;
using QC.QTMInterface;

namespace QC.QTMApplication;

internal class ParameterValueRule : ValidationRule
{
	private ParameterCls tParam;

	public ParameterCls Parameter
	{
		get
		{
			return tParam;
		}
		set
		{
			tParam = value;
		}
	}

	public override ValidationResult Validate(object value, CultureInfo cultureInfo)
	{
		if (tParam.DataType == DataType.Int || tParam.DataType == DataType.Int16 || tParam.DataType == DataType.Int64 || tParam.DataType == DataType.SByte || tParam.DataType == DataType.UInt16 || tParam.DataType == DataType.UInt32 || tParam.DataType == DataType.UInt64 || tParam.DataType == DataType.Byte)
		{
			long result = -1L;
			if (long.TryParse(value.ToString(), out result))
			{
				return ValidationResult.ValidResult;
			}
			return new ValidationResult(isValid: false, "Data is not valid");
		}
		if (tParam.DataType == DataType.Double || tParam.DataType == DataType.Single || tParam.DataType == DataType.Decimal)
		{
			double result2 = -1.0;
			if (double.TryParse(value.ToString(), out result2))
			{
				return ValidationResult.ValidResult;
			}
			return new ValidationResult(isValid: false, "Data is not valid");
		}
		return ValidationResult.ValidResult;
	}
}
