using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Windows.Media;
using BS.Shared.Core;
using BS.Shared.DataContracts.Compact;

namespace BS.Shared.DataContracts
{
    [DataContract]
    public class AdditionalServiceGroupOfPeopleDC : IDataContract, IFilterableDC
    {
        [DataMember]
        public long? AdditionalServiceGroupOfPeopleOid { set; get; }

        [DataMember]
        public long? AdditionalServiceGroupOfPeopleVersion { set; get; }

        [DataMember]
        public AppointmentDayOfWeek AppointmentDayOfWeek { get; set; }

        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public List<CompactCustomerDC> CustomerList { get; set; }

        public override string ToString()
        {
            return Name;
        }

        [DataMember]
        public ActivationTypeId ActivationType { get; set; }

        public string DetailDescription { get { return Name + "\n" + AppointmentDayOfWeek; } }

        public string FilterRelevants 
        { 
            get { return "FILTERRELEVANT"; } 
        }
        
        public string IconPath
        {
            get { return @"..\..\Ressources\Icons\UserGroupDisabled.png"; }
        }
        
        public string SimpleDescription
        {
            get
            {
                return ToString();
            }
        }
        
        public bool SupportsActivationType
        {
            get
            {
                return true;
            }
        }
        
        public long Version
        {
            get
            {
                return AdditionalServiceGroupOfPeopleVersion.Value;
            }

            set
            {
                AdditionalServiceGroupOfPeopleVersion = value;
            }
        }

        public SolidColorBrush FilterableBrush { get { return new SolidColorBrush(Colors.Transparent); } }

        public Brush ForegroundBrush
        {
            get { return new SolidColorBrush(Color.FromRgb(160, 160, 160)); }
        }

        public ObservableSortCollection<AdditionalServiceGroupMember> GetGroupMembers()
        {
            var result = new ObservableSortCollection<AdditionalServiceGroupMember>();

            foreach (var customer in CustomerList)
                result.Add(new AdditionalServiceGroupMember(customer, this));

            return result;
        }
    }

    public class AdditionalServiceGroupMember
    {
        public CompactCustomerDC Customer { get; set; }
        public AppointmentDayOfWeek AppointmentDayOfWeek { get; set; }
        public string GroupName { get; set; }

        public AdditionalServiceGroupMember(CompactCustomerDC customer, AdditionalServiceGroupOfPeopleDC group)
        {
            Customer = customer;
            AppointmentDayOfWeek = group.AppointmentDayOfWeek;
            GroupName = group.Name;
        }
    }
}
