using System;
using System.Collections.Generic;

namespace TeslaConsole;

public class HostTypeHelper
{
	private static readonly Dictionary<HostType, HostTypeHelper> mCache;

	private HostType mHostType;

	public HostType HostType => mHostType;

	static HostTypeHelper()
	{
		mCache = new Dictionary<HostType, HostTypeHelper>();
		foreach (object value in Enum.GetValues(typeof(HostType)))
		{
			HostType hostType = (HostType)value;
			mCache.Add(hostType, new HostTypeHelper(hostType));
		}
	}

	public static explicit operator HostTypeHelper(HostType hostType)
	{
		return mCache[hostType];
	}

	public static explicit operator HostType(HostTypeHelper helper)
	{
		return helper.HostType;
	}

	public static bool operator ==(HostTypeHelper a, HostTypeHelper b)
	{
		return a.mHostType == b.mHostType;
	}

	public static bool operator !=(HostTypeHelper a, HostTypeHelper b)
	{
		return !(a == b);
	}

	public static HostTypeHelper Parse(string str)
	{
		foreach (HostTypeHelper value in mCache.Values)
		{
			if (value.ToString() == str)
			{
				return value;
			}
		}
		try
		{
			HostType hostType = (HostType)Enum.Parse(typeof(HostType), str);
			return (HostTypeHelper)hostType;
		}
		catch (Exception)
		{
		}
		throw new ArgumentException();
	}

	private HostTypeHelper(HostType hostType)
	{
		mHostType = hostType;
	}

	public override bool Equals(object obj)
	{
		if (obj is HostTypeHelper && ((HostTypeHelper)obj).mHostType == mHostType)
		{
			return true;
		}
		return false;
	}

	public override int GetHashCode()
	{
		return (int)mHostType;
	}

	public override string ToString()
	{
		return mHostType switch
		{
			HostType.GameMachineHostType => "Game Machine", 
			HostType.MissionReviewHostType => "Mission Review", 
			HostType.ConsoleHostType => "Console", 
			_ => mHostType.ToString(), 
		};
	}
}
