using QC.QTMXmlSchema;

namespace QC.XmlToDBPreProcess;

internal class SplitErrorCode : IPreProcess
{
	private const int ERRORCODE_LENGTH = 4;

	private const string MAIN_ERRORCODE = "MainErr";

	private const string SUB_ERRORCODE = "SubErr";

	public ConversionType ApplyPreProcessType(ref ROOT qtmXml, string[] Arguments)
	{
		if (qtmXml.ConfigInfo.ERROR_CODE == null || qtmXml.ConfigInfo.ERROR_CODE == string.Empty)
		{
			return ConversionType.All;
		}
		string eRROR_CODE = qtmXml.ConfigInfo.ERROR_CODE;
		string text = eRROR_CODE.Substring(4);
		ROOTConfigInfo[] information = qtmXml.ConfigInfo.Information;
		int num = ((text == null || text == string.Empty) ? 1 : 2);
		if (information != null)
		{
			num += information.Length;
		}
		ROOTConfigInfo[] array = new ROOTConfigInfo[num];
		ROOTConfigInfo rOOTConfigInfo = new ROOTConfigInfo();
		rOOTConfigInfo.Key = "MainErr";
		rOOTConfigInfo.Value = eRROR_CODE.Substring(0, 4);
		information?.CopyTo(array, 0);
		array.SetValue(rOOTConfigInfo, array.Length - 1);
		string text2 = qtmXml.ConfigInfo.RunTitle;
		if (text2.Length != 0)
		{
			text2 += "_ _";
		}
		text2 = text2 + rOOTConfigInfo.Key + "__" + rOOTConfigInfo.Value;
		text2 += "_ _";
		if (num > 1)
		{
			ROOTConfigInfo rOOTConfigInfo2 = new ROOTConfigInfo();
			rOOTConfigInfo2.Key = "SubErr";
			rOOTConfigInfo2.Value = text;
			array.SetValue(rOOTConfigInfo2, array.Length - 2);
			text2 = text2 + rOOTConfigInfo2.Key + "__" + rOOTConfigInfo2.Value;
		}
		qtmXml.ConfigInfo.Information = array;
		qtmXml.ConfigInfo.RunTitle = text2;
		return ConversionType.All;
	}
}
