using System;
using QC.QTMDotNetKernelInterface;

namespace QC.QTMToolKit;

[QTMTestClass]
internal class StringManipulation
{
	[QTMParameter(ArgumentName = "intResult", DefaultValue = "0", Description = "returns 0 if it's the same, -1 if less than and 1 if it's greater than.", NumberOfElements = 1)]
	[QTMParameter(ArgumentName = "IgnoreCase", DefaultValue = "Yes", Description = "Yes to indicate a case-insenstive comparision.", NumberOfElements = 1, DisplayHint = DisplayHints.YESNO)]
	[QTMParameter(ArgumentName = "String2", DefaultValue = "string2", Description = "Enter second string value.", NumberOfElements = 1)]
	[QTMTest(Description = "Compares two strings and returns 0 if it's the same, -1 if less than and 1 if it's greater than.", CanAddToTestPlan = true)]
	[QTMParameter(ArgumentName = "String1", DefaultValue = "string1", Description = "Enter first string value.", NumberOfElements = 1)]
	public bool CompareStrings(string String1, string String2, bool IgnoreCase, out string ErrorMessage, out int intResult)
	{
		ErrorMessage = "";
		try
		{
			intResult = string.Compare(String1.Trim(), String2.Trim(), IgnoreCase);
		}
		catch (Exception ex)
		{
			ErrorMessage = ex.Message;
			intResult = -1;
			return false;
		}
		return true;
	}

	[QTMParameter(ArgumentName = "StringSeparator", DefaultValue = "_", Description = "Enter a separator to separate two strings.", NumberOfElements = 1)]
	[QTMTest(Description = "Combines two strings and returns the concatenation of string1, separator, and string2.", CanAddToTestPlan = true)]
	[QTMParameter(ArgumentName = "String1", DefaultValue = "string1", Description = "Enter first string value.", NumberOfElements = 1)]
	[QTMParameter(ArgumentName = "String2", DefaultValue = "string2", Description = "Enter second string value.", NumberOfElements = 1)]
	public bool CombineStrings(string String1, string String2, string StringSeparator, out string ResultString)
	{
		ResultString = "";
		try
		{
			ResultString = String1 + StringSeparator + String2;
		}
		catch (Exception ex)
		{
			ResultString = ex.Message;
			return false;
		}
		return true;
	}

	[QTMParameter(ArgumentName = "IgnoreCase", DefaultValue = "Yes", Description = "Yes to indicate a case-insenstive comparision.", NumberOfElements = 1, DisplayHint = DisplayHints.YESNO)]
	[QTMParameter(ArgumentName = "String1", DefaultValue = "string1", Description = "Enter first string value.", NumberOfElements = 1)]
	[QTMParameter(ArgumentName = "String2", DefaultValue = "string2", Description = "Enter second string value.", NumberOfElements = 1)]
	[QTMParameter(ArgumentName = "intResult", DefaultValue = "0", Description = "returns 0 if string1 ends with string2, returns -1 otherwise.", NumberOfElements = 1)]
	[QTMTest(Description = "Returns 0 if string1 ends with string2, returns -1 otherwise.", CanAddToTestPlan = true)]
	public bool EndWithString(string String1, string String2, bool IgnoreCase, string StringSeparator, out string ErrorMessage, out int intResult)
	{
		ErrorMessage = "";
		try
		{
			if (String1.EndsWith(String2, IgnoreCase, null))
			{
				intResult = 0;
			}
			else
			{
				intResult = -1;
			}
		}
		catch (Exception ex)
		{
			ErrorMessage = ex.Message;
			intResult = -1;
			return false;
		}
		return true;
	}

	[QTMParameter(ArgumentName = "IgnoreCase", DefaultValue = "Yes", Description = "Yes to indicate a case-insenstive comparision.", NumberOfElements = 1, DisplayHint = DisplayHints.YESNO)]
	[QTMParameter(ArgumentName = "String2", DefaultValue = "string2", Description = "Enter second string value.", NumberOfElements = 1)]
	[QTMParameter(ArgumentName = "intResult", DefaultValue = "0", Description = "0 if string1 starts with string2, returns -1 otherwise.", NumberOfElements = 1)]
	[QTMTest(Description = "Returns 0 if string1 starts with string2, returns -1 otherwise.", CanAddToTestPlan = true)]
	[QTMParameter(ArgumentName = "String1", DefaultValue = "string1", Description = "Enter first string value.", NumberOfElements = 1)]
	public bool StartWithString(string String1, string String2, bool IgnoreCase, out string ErrorMessage, out int intResult)
	{
		ErrorMessage = "";
		try
		{
			if (String1.StartsWith(String2, IgnoreCase, null))
			{
				intResult = 0;
			}
			else
			{
				intResult = -1;
			}
		}
		catch (Exception ex)
		{
			ErrorMessage = ex.Message;
			intResult = -1;
			return false;
		}
		return true;
	}

	[QTMParameter(ArgumentName = "String1", DefaultValue = "string1", Description = "Enter first string value.", NumberOfElements = 1)]
	[QTMParameter(ArgumentName = "intResult", DefaultValue = "0", Description = "returns 0 if string1 contains string2, returns -1 otherwise.", NumberOfElements = 1)]
	[QTMParameter(ArgumentName = "String2", DefaultValue = "string2", Description = "Enter second string value.", NumberOfElements = 1)]
	[QTMTest(Description = "Returns 0 if string1 contains string2, returns -1 otherwise.", CanAddToTestPlan = true)]
	[QTMParameter(ArgumentName = "IgnoreCase", DefaultValue = "Yes", Description = "Yes to indicate a case-insenstive comparision.", NumberOfElements = 1, DisplayHint = DisplayHints.YESNO)]
	public bool ContainString(string String1, string String2, bool IgnoreCase, out string ErrorMessage, out int intResult)
	{
		ErrorMessage = "";
		try
		{
			if ((IgnoreCase && String1.ToUpper().Trim().Contains(String2.ToUpper().Trim())) || (!IgnoreCase && String1.Trim().Contains(String2.Trim())))
			{
				intResult = 0;
			}
			else
			{
				intResult = -1;
			}
		}
		catch (Exception ex)
		{
			ErrorMessage = ex.Message;
			intResult = -1;
			return false;
		}
		return true;
	}

	[QTMTest(Description = "Add Date to string.", CanAddToTestPlan = true)]
	[QTMParameter(ArgumentName = "String1", DefaultValue = "string1", Description = "Enter string value.", NumberOfElements = 1)]
	public string AddDateToString(string String1)
	{
		return String1 + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Year;
	}
}
