using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Connected.Utilities;
public static class Helper
{
	public static string GetEnumDescription<T>(T EnumVariable)
	{
		string result = string.Empty;

		if (!typeof(T).IsEnum)
			return string.Empty;

		result = EnumVariable.ToString();

		var fieldInfo = EnumVariable.GetType().GetField(EnumVariable.ToString());

		if (fieldInfo != null)
		{
			var attrs = fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), true);
			if (attrs != null && attrs.Length > 0)
			{
				result = ((DescriptionAttribute)attrs[0]).Description;
			}
		}

		return result;
	}

	public static bool IsTypeNumeric(string type)
	{
		switch (type.ToLower())
		{
			case "uint16":
			case "uint32":
			case "uint64":
			case "int16":
			case "int32":
			case "int64":
			case "int":
			case "double":
			case "decimal":
			case "float":
				return true;
			default:
				return false;
		}
	}

	public static bool IsTypeDate(string type)
	{
		switch (type.ToLower())
		{
			case "datetime":
			case "dateonly":
			case "timeonly":
				return true;
			default:
				return false;
		}
	}

	public static bool IsTypeString(string type)
	{
		switch (type.ToLower())
		{
			case "string":
				return true;
			default:
				return false;
		}
	}

	public static bool IsVariableNumeric(string input)
	{
		try
		{
			var number = Double.Parse(input);
			return true;
		}
		catch
		{
			return false;
		}
	}
}
