using System;
using System.Collections.Generic;
using System.Linq;

namespace InABox.Core
{
    public class DigitalFormCategoryLookups : LookupGenerator<object>
    {
        public DigitalFormCategoryLookups(object[]? items) : base(items)
        {
            var lookups = new Dictionary<string, string>(); // { { "", "Select Category" } };

            var types = CoreUtils.TypeList(
                AppDomain.CurrentDomain.GetAssemblies(),
                x => !x.IsAbstract && x.GetInterfaces().Contains(typeof(IDigitalForm)) // &&  !x.GetInterfaces().Contains(typeof(IQAInstance))
            ).ToArray();

            foreach (var type in types)
            {
                var forms = type.GetInterfaces().Where(x => x.GetInterfaces().Contains(typeof(IDigitalForm)) && x.IsGenericType);
                foreach (var form in forms)
                foreach (var generic in form.GenericTypeArguments)
                    lookups[generic.EntityName().Split('.').Last()] = generic.GetCaption();
            }

            foreach (var key in lookups.Keys)
                AddValue(key, lookups[key]);
        }
    }
}