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

namespace NaughtyAttributes {
    [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
    public class DropdownAttribute : DrawerAttribute {
        public string ValuesFieldName { get; private set; }

        public DropdownAttribute (string valuesFieldName) => this.ValuesFieldName = valuesFieldName;
    }

    public interface IDropdownList : IEnumerable<KeyValuePair<string, object>> {
    }

    public class DropdownList<T> : IDropdownList {
        private List<KeyValuePair<string, object>> values;

        public DropdownList () => this.values = new List<KeyValuePair<string, object>>();

        public void Add (string displayName, T value) => this.values.Add(new KeyValuePair<string, object>(displayName, value));

        public IEnumerator<KeyValuePair<string, object>> GetEnumerator () => this.values.GetEnumerator();

        IEnumerator IEnumerable.GetEnumerator () => this.GetEnumerator();

        public static explicit operator DropdownList<object>(DropdownList<T> target) {
            DropdownList<object> result = new DropdownList<object>();
            foreach (var kvp in target) {
                result.Add(kvp.Key, kvp.Value);
            }

            return result;
        }
    }
}
