using System;
using System.Collections.Generic;
using Assets.Scripts;
using Swan;

namespace RemoteControl.Utils
{
    internal static class Extensions
    {
        internal static Dictionary<string, TEnum> AsLookupDict<TEnum, TValue>(this EnumCollection<TEnum, TValue> collection, bool lowercase)
            where TEnum : Enum, IConvertible, new()
            where TValue : IConvertible, IEquatable<TValue>
        {
            var result = new Dictionary<string, TEnum>();
            for (var i = 0; i < collection.Length; i++)
            {
                var name = collection.Names[i];
                if (lowercase)
                {
                    name = name.ToLowerInvariant();
                }
                var value = collection.Values[i];
                result.Add(name, value);
                result.Add(collection.ValuesAsInts[i].ToStringInvariant(), value);
            }
            return result;
        }
    }
}