using System;
using System.Reflection;
using Microsoft.Office.Interop.Excel;

namespace QC.CorpTest.Libraries.ExcelLibrary;

public static class ExcelOptionsMapper
{
	public static object GetPlatform(object platformOptionAsString)
	{
		if (platformOptionAsString.GetType() == typeof(Missing) || platformOptionAsString.GetType() == Type.Missing)
		{
			return Type.Missing;
		}
		return Convert.ToString(platformOptionAsString) switch
		{
			"xlMacintosh" => (object)(XlPlatform)1, 
			"xlMSDOS" => (object)(XlPlatform)3, 
			"xlWindows" => (object)(XlPlatform)2, 
			_ => Type.Missing, 
		};
	}

	public static object GetCorruptLoad(object corruptLoadOptionAsString)
	{
		if (corruptLoadOptionAsString.GetType() == typeof(Missing) || corruptLoadOptionAsString.GetType() == Type.Missing)
		{
			return Type.Missing;
		}
		return Convert.ToString(corruptLoadOptionAsString) switch
		{
			"xlExtractData" => (object)(XlCorruptLoad)2, 
			"xlNormalLoad" => (object)(XlCorruptLoad)0, 
			"xlRepairFile" => (object)(XlCorruptLoad)1, 
			_ => Type.Missing, 
		};
	}

	public static object GetTemplate(object templateAsString)
	{
		if (templateAsString.GetType() == typeof(Missing) || templateAsString.GetType() == Type.Missing)
		{
			return Type.Missing;
		}
		string text = Convert.ToString(templateAsString);
		switch (text)
		{
		case "xlWBATChart":
			return (object)(XlWBATemplate)(-4109);
		case "xlWBATExcel4IntlMacroSheet":
			return (object)(XlWBATemplate)4;
		case "xlWBATExcel4MacroSheet":
			return (object)(XlWBATemplate)3;
		case "xlWBATWorksheet":
			return (object)(XlWBATemplate)(-4167);
		default:
			if (text.Length > 0)
			{
				return templateAsString;
			}
			return Type.Missing;
		}
	}

	public static object GetSaveConflictResolution(object saveConflictResolutionAsString)
	{
		if (saveConflictResolutionAsString.GetType() == typeof(Missing) || saveConflictResolutionAsString.GetType() == Type.Missing)
		{
			return Type.Missing;
		}
		return Convert.ToString(saveConflictResolutionAsString) switch
		{
			"xlLocalSessionChanges" => (object)(XlSaveConflictResolution)2, 
			"xlOtherSessionChanges" => (object)(XlSaveConflictResolution)3, 
			"xlUserResolution" => (object)(XlSaveConflictResolution)1, 
			_ => Type.Missing, 
		};
	}

	public static XlSaveAsAccessMode GetSaveAccessNode(object accessModeAsString)
	{
		if (accessModeAsString.GetType() == typeof(Missing) || accessModeAsString.GetType() == Type.Missing)
		{
			return (XlSaveAsAccessMode)1;
		}
		return (XlSaveAsAccessMode)(Convert.ToString(accessModeAsString) switch
		{
			"xlExclusive" => 3, 
			"xlNoChange" => 1, 
			"xlShared" => 2, 
			_ => 1, 
		});
	}

	public static XlHAlign GetHorizontalAlignment(string horizontalAlignment)
	{
		return (XlHAlign)(horizontalAlignment switch
		{
			"xlHAlignCenter" => -4108, 
			"xlHAlignCenterAcrossSelection" => 7, 
			"xlHAlignDistributed" => -4117, 
			"xlHAlignFill" => 5, 
			"xlHAlignGeneral" => 1, 
			"xlHAlignJustify" => -4130, 
			"xlHAlignLeft" => -4131, 
			"xlHAlignRight" => -4152, 
			_ => 1, 
		});
	}

	public static XlVAlign GetVerticalAlignment(string verticalAlignment)
	{
		return (XlVAlign)(verticalAlignment switch
		{
			"xlVAlignBottom" => -4107, 
			"xlVAlignCenter" => -4108, 
			"xlVAlignDistributed" => -4117, 
			"xlVAlignJustify" => -4130, 
			"xlVAlignTop" => -4160, 
			_ => -4107, 
		});
	}

	public static XlUnderlineStyle GetUnderLineStyle(string underLineStyle)
	{
		return (XlUnderlineStyle)(underLineStyle switch
		{
			"xlUnderlineStyleDouble" => -4119, 
			"xlUnderlineStyleDoubleAccounting" => 5, 
			"xlUnderlineStyleNone" => -4142, 
			"xlUnderlineStyleSingle" => 2, 
			"xlUnderlineStyleSingleAccounting" => 4, 
			_ => -4142, 
		});
	}

	public static object GetColorIndex(string colorIndex)
	{
		if (ExcelConstants.ColorIndexOptions.GetValues().Contains(colorIndex))
		{
			return colorIndex switch
			{
				"xlColorIndexAutomatic" => (object)(XlColorIndex)(-4105), 
				"xlColorIndexNone" => (object)(XlColorIndex)(-4142), 
				_ => (object)(XlColorIndex)(-4105), 
			};
		}
		if (int.TryParse(colorIndex, out var result))
		{
			return result;
		}
		return (object)(XlColorIndex)(-4105);
	}

	public static XlPattern GetPattern(string pattern)
	{
		return (XlPattern)(pattern switch
		{
			"xlPatternAutomatic" => -4105, 
			"xlPatternChecker" => 9, 
			"xlPatternCrissCross" => 16, 
			"xlPatternDown" => -4121, 
			"xlPatternGray16" => 17, 
			"xlPatternGray25" => -4124, 
			"xlPatternGray50" => -4125, 
			"xlPatternGray75" => -4126, 
			"xlPatternGray8" => 18, 
			"xlPatternGrid" => 15, 
			"xlPatternHorizontal" => -4128, 
			"xlPatternLightDown" => 13, 
			"xlPatternLightHorizontal" => 11, 
			"xlPatternLightUp" => 14, 
			"xlPatternLightVertical" => 12, 
			"xlPatternNone" => -4142, 
			"xlPatternSemiGray75" => 10, 
			"xlPatternSolid" => 1, 
			"xlPatternUp" => -4162, 
			"xlPatternVertical" => -4166, 
			_ => -4142, 
		});
	}

	public static object GetChartType(string chartType)
	{
		return chartType switch
		{
			"xl3DArea" => (object)(XlChartType)(-4098), 
			"xl3DAreaStacked" => (object)(XlChartType)78, 
			"xl3DAreaStacked100" => (object)(XlChartType)79, 
			"xl3DBarClustered" => (object)(XlChartType)60, 
			"xl3DBarStacked" => (object)(XlChartType)61, 
			"xl3DBarStacked100" => (object)(XlChartType)62, 
			"xl3DColumn" => (object)(XlChartType)(-4100), 
			"xl3DColumnClustered" => (object)(XlChartType)54, 
			"xl3DColumnStacked" => (object)(XlChartType)55, 
			"xl3DColumnStacked100" => (object)(XlChartType)56, 
			"xl3DLine" => (object)(XlChartType)(-4101), 
			"xl3DPie" => (object)(XlChartType)(-4102), 
			"xl3DPieExploded" => (object)(XlChartType)70, 
			"xlArea" => (object)(XlChartType)1, 
			"xlAreaStacked" => (object)(XlChartType)76, 
			"xlAreaStacked100" => (object)(XlChartType)77, 
			"xlBarClustered" => (object)(XlChartType)57, 
			"xlBarOfPie" => (object)(XlChartType)71, 
			"xlBarStacked" => (object)(XlChartType)58, 
			"xlBarStacked100" => (object)(XlChartType)59, 
			"xlBubble" => (object)(XlChartType)15, 
			"xlBubble3DEffect" => (object)(XlChartType)87, 
			"xlColumnClustered" => (object)(XlChartType)51, 
			"xlColumnStacked" => (object)(XlChartType)52, 
			"xlColumnStacked100" => (object)(XlChartType)53, 
			"xlConeBarClustered" => (object)(XlChartType)102, 
			"xlConeBarStacked" => (object)(XlChartType)103, 
			"xlConeBarStacked100" => (object)(XlChartType)104, 
			"xlConeCol" => (object)(XlChartType)105, 
			"xlConeColClustered" => (object)(XlChartType)99, 
			"xlConeColStacked" => (object)(XlChartType)100, 
			"xlConeColStacked100" => (object)(XlChartType)101, 
			"xlCylinderBarClustered" => (object)(XlChartType)95, 
			"xlCylinderBarStacked" => (object)(XlChartType)96, 
			"xlCylinderBarStacked100" => (object)(XlChartType)97, 
			"xlCylinderCol" => (object)(XlChartType)98, 
			"xlCylinderColClustered" => (object)(XlChartType)92, 
			"xlCylinderColStacked" => (object)(XlChartType)93, 
			"xlCylinderColStacked100" => (object)(XlChartType)94, 
			"xlDoughnut" => (object)(XlChartType)(-4120), 
			"xlDoughnutExploded" => (object)(XlChartType)80, 
			"xlLine" => (object)(XlChartType)4, 
			"xlLineMarkers" => (object)(XlChartType)65, 
			"xlLineMarkersStacked" => (object)(XlChartType)66, 
			"xlLineMarkersStacked100" => (object)(XlChartType)67, 
			"xlLineStacked" => (object)(XlChartType)63, 
			"xlLineStacked100" => (object)(XlChartType)64, 
			"xlPie" => (object)(XlChartType)5, 
			"xlPieExploded" => (object)(XlChartType)69, 
			"xlPieOfPie" => (object)(XlChartType)68, 
			"xlPyramidBarClustered" => (object)(XlChartType)109, 
			"xlPyramidBarStacked" => (object)(XlChartType)110, 
			"xlPyramidBarStacked100" => (object)(XlChartType)111, 
			"xlPyramidCol" => (object)(XlChartType)112, 
			"xlPyramidColClustered" => (object)(XlChartType)106, 
			"xlPyramidColStacked" => (object)(XlChartType)107, 
			"xlPyramidColStacked100" => (object)(XlChartType)108, 
			"xlRadar" => (object)(XlChartType)(-4151), 
			"xlRadarFilled" => (object)(XlChartType)82, 
			"xlRadarMarkers" => (object)(XlChartType)81, 
			"xlStockHLC" => (object)(XlChartType)88, 
			"xlStockOHLC" => (object)(XlChartType)89, 
			"xlStockVHLC" => (object)(XlChartType)90, 
			"xlStockVOHLC" => (object)(XlChartType)91, 
			"xlSurface" => (object)(XlChartType)83, 
			"xlSurfaceTopView" => (object)(XlChartType)85, 
			"xlSurfaceTopViewWireframe" => (object)(XlChartType)86, 
			"xlSurfaceWireframe" => (object)(XlChartType)84, 
			"xlXYScatter" => (object)(XlChartType)(-4169), 
			"xlXYScatterLines" => (object)(XlChartType)74, 
			"xlXYScatterLinesNoMarkers" => (object)(XlChartType)75, 
			"xlXYScatterSmooth" => (object)(XlChartType)72, 
			"xlXYScatterSmoothNoMarkers" => (object)(XlChartType)73, 
			_ => Type.Missing, 
		};
	}

	public static object GetChartFormat(string chartFormat)
	{
		if (int.TryParse(chartFormat, out var result))
		{
			if (result > 0 && result < 11)
			{
				return result;
			}
			return Type.Missing;
		}
		return Type.Missing;
	}

	public static object GetRowCol(string rowCol)
	{
		return rowCol switch
		{
			"xlColumns" => (object)(XlRowCol)2, 
			"xlRows" => (object)(XlRowCol)1, 
			_ => Type.Missing, 
		};
	}

	public static XlChartLocation GetChartLocation(string chartLocation)
	{
		return (XlChartLocation)(chartLocation switch
		{
			"xlLocationAsNewSheet" => 1, 
			"xlLocationAsObject" => 2, 
			"xlLocationAutomatic" => 3, 
			_ => 3, 
		});
	}

	public static XlAxisGroup GetAxisGroup(string axisGroup)
	{
		return (XlAxisGroup)(axisGroup switch
		{
			"xlPrimary" => 1, 
			"xlSecondary" => 2, 
			_ => 1, 
		});
	}

	public static XlAxisType GetChartAxisType(string axisType)
	{
		return (XlAxisType)(axisType switch
		{
			"xlCategory" => 1, 
			"xlSeriesAxis" => 3, 
			"xlValue" => 2, 
			_ => 1, 
		});
	}

	public static XlLineStyle GetLineStyle(string lineStyle)
	{
		return (XlLineStyle)(lineStyle switch
		{
			"xlContinuous" => 1, 
			"xlDash" => -4115, 
			"xlDashDot" => 4, 
			"xlDashDotDot" => 5, 
			"xlDot" => -4118, 
			"xlDouble" => -4119, 
			"xlLineStyleNone" => -4142, 
			"xlSlantDashDot" => 13, 
			_ => -4142, 
		});
	}

	public static XlBordersIndex GetBordersIndex(int bordersIndex)
	{
		return (XlBordersIndex)(bordersIndex switch
		{
			5 => 5, 
			6 => 6, 
			9 => 9, 
			7 => 7, 
			10 => 10, 
			8 => 8, 
			12 => 12, 
			11 => 11, 
			_ => 7, 
		});
	}

	public static XlLegendPosition GetLegendPosition(string legendPosition)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		return (XlLegendPosition)(legendPosition switch
		{
			"Bottom" => -4107, 
			"Left" => -4131, 
			"Right" => -4152, 
			"TopRight" => 2, 
			_ => 2, 
		});
	}
}
