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

using EPiServer.Personalization.VisitorGroups;
using EPiServer.Shell.ObjectEditing;

using EPiServer.ServiceLocation;

using ISelectionFactory = EPiServer.Shell.ObjectEditing.ISelectionFactory;

namespace GMGShop.Model.SelectionFactory
{
    public class VisitorGroupSelectionFactory : ISelectionFactory
    {
        internal Injected<IVisitorGroupRepository>  VisitorGroupRepository;

        public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
        {
            return
                VisitorGroupRepository.Service.List()
                    .OrderBy(v => v.Name)
                    .Select(v => new SelectItem { Text = v.Name, Value = v.Id });
        }
    }
}