using System;
using System.Globalization;
using System.Linq;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;

namespace VOID.Generic.DynamicValue.Markers
{
    public class UnitResourceCurrentMarkerGroup : IMarkerGroup
    {
        public string Group() => "UnitResource.Current";
        
        public string[] Markers() =>
            Enum.GetValues(typeof(UnitResourceType))
                .OfType<Enum>()
                .Select(@enum => @enum.ToString())
                .ToArray();

        public Type SourceType() => typeof(UnitObject);

        public Type ResultType() => typeof(float);
        
        public Func<string> Getter(object source, string marker)
        {
            var @enum = Enum.Parse<UnitResourceType>(marker, true);
            return () => ((UnitObject)source).unitData.currentResources.Get(@enum).ToString(CultureInfo.InvariantCulture);
        }
    }
}