using System.Linq;

namespace InABox.Core
{
    [UserTracking(typeof(User))]
    [Caption("Security Defaults")]
    [Unrecoverable]
    public class GlobalSecurityToken : Entity, IPersistent, IRemotable, ILicense<CoreLicense>
    {
        [ComboLookupEditor(typeof(SecurityRestrictionGenerator))]
        public string Descriptor { get; set; }

        [CheckBoxEditor]
        public bool Enabled { get; set; }

        public override string ToString()
        {
            return Descriptor;
        }

        private class SecurityRestrictionGenerator : LookupGenerator<object>
        {
            public SecurityRestrictionGenerator(object[] items) : base(items)
            {
                foreach (var descriptor in Security.Descriptors.Where(x => x.HasScope(SecurityDescriptorScope.Global)))
                    AddValue(descriptor.Code, descriptor.Description);
            }
        }
    }
}