using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace ChatController.ChatKlassen
{
    public class KontaktlistBuilder
    {

        public string Name { get; private set; }

        private string _receiveMs;
        public string ReceiveMs
        {
            get
            {
                if (!String.IsNullOrEmpty(_receiveMs) && _receiveMs.Length > 25)
                {
                    return _receiveMs.Substring(0, 25) + "...";
                }
                return _receiveMs;
                
                //var WordsArray = _receiveMs.Split();

                ////var verkuerzterText = _receiveMs.Substring(0,10);
                //if (WordsArray.Length > 4)
                //{
                //    string Items = WordsArray[0] + " " + WordsArray[1] + " " + WordsArray[2] + " " + WordsArray[3] + "...";

                //    return Items;
                //}
                //else
                //{
                //    //if(_receiveMs.Length > 15)
                //    return _receiveMs;
                //}
            }

            set
            {
                _receiveMs = value;
                OnPropertyChanged("ReceiveMs");
            }
        }

        private Brush _color;
        public Brush Color
        {
            get
            {
                return _color;
            }
            set
            {
               
                _color = value;

                OnPropertyChanged("Color");
            }
        }

        private int _setzeGelesen;
        public int SetzeGelesen
        {
            get { return _setzeGelesen; }

            set
            {
                _setzeGelesen = value;
                    
                if (_setzeGelesen == 1)
                {
                    _color = new BrushConverter().ConvertFromString("#ff5e00") as SolidColorBrush;
                }
                else 
                {
                    _color = new SolidColorBrush(Colors.Gray);
                }

                OnPropertyChanged("SetzeGelesen");
                OnPropertyChanged("Color");
            }
        }

        private Brush _kontaktChatColor;
        public Brush KontaktChatColor
        {
            get
            {
                return _kontaktChatColor;
            }
            set
            {

                _kontaktChatColor = value;

                OnPropertyChanged("KontaktChatColor");
            }
        }

        public ImageSource Image { get; private set; }
        public DateTime TimeStamp { get; set; }
        public long GroupId { get; set; }
        public long UserId { get; set; }
        public long? CustomerOid { get; set; }

        public KontaktlistBuilder(string name, ImageSource image, string lastMs, DateTime timestamp, long groupid,long? customerOid, bool onlyEmployee, int userCount)
        {

#if DEBUG
            //lastMs =
            //    "aas dgfal Dies ist ein laaaaaanger Text !Q!!! adg asgl sadlg jasg jas,g ans,g nasgd., a ag fdgg agsd g";
            //name = "Hans Hubert Christopherus Maximilian Schumacherus";
#endif

            Name = name;
            ReceiveMs = lastMs;
            Image = image;
            TimeStamp = timestamp;
            GroupId = groupid;
            CustomerOid = customerOid;
            SetzeGelesen = 1;





            if (CustomerOid != null)
            {
                _kontaktChatColor = new BrushConverter().ConvertFromString("#3B7799") as SolidColorBrush;
            }else if (onlyEmployee && userCount > 2)
            {
              
                //Alle gruppen werden grün 
                _kontaktChatColor = new BrushConverter().ConvertFromString("#45993B") as SolidColorBrush;

            }
            else
            {
                //Alles bleibt wie es war also schwarz
                _kontaktChatColor = new BrushConverter().ConvertFromString("#000000") as SolidColorBrush;

            }
            

        }

        //public KontaktlistBuilder(string name, StatusType statustyp, ImageSource image, long empfaengerid, ChatType typeChat, CompactCustomerDC customer)
        //{
        //    this.Customer = customer;
        //    this.Name = name;
        //    this.StatusTyp = statustyp;
        //    this.Image = image;
        //    this.EmpfaengerOid = empfaengerid;

        //    Receivems = "";
        //    TypeChat = typeChat;

        //    if (statustyp == StatusType.Online)
        //    {
        //        this.Color = new BrushConverter().ConvertFromString("#00ae00") as SolidColorBrush;
        //    }
        //    else if (statustyp == StatusType.Offline)
        //    {
        //        this.Color = new SolidColorBrush(Colors.Red);
        //    }
        //    else
        //    {
        //        this.Color = new SolidColorBrush(Colors.Orange);
        //    }

        //    if (typeChat == ChatType.Team)
        //    {
        //        _colorType = new SolidColorBrush(Colors.DarkViolet);
        //    }
        //    else if (typeChat == ChatType.Klienten)
        //    {
        //        _colorType = new SolidColorBrush(Colors.Blue);
        //    }
        //    else
        //    {
        //        _colorType = new SolidColorBrush(Colors.Green);
        //    }
        //}

        //public string Name { get; private set; }

        //private StatusType _statustyp;
        //public StatusType StatusTyp
        //{
        //    get { return _statustyp; }
        //    set
        //    {
        //        _statustyp = value;

        //        if (_statustyp == StatusType.Online)
        //        {
        //            _color = new BrushConverter().ConvertFromString("#00ae00") as SolidColorBrush;
        //        }
        //        else if (_statustyp == StatusType.Offline)
        //        {
        //            _color = new SolidColorBrush(Colors.Red);
        //        }
        //        else
        //        {
        //            _color = new SolidColorBrush(Colors.Orange);
        //        }

        //        OnPropertyChanged("Lastms");
        //    }
        //}

        //public ImageSource Image { get; private set; }

        //public long EmpfaengerOid { get; private set; }

        //private string _receivems;
        //public string Receivems { get { return _receivems; } set { _receivems = value; OnPropertyChanged("Receivems"); } }

        //public ChatType TypeChat { get; set; }

        //private Brush _color;
        //public Brush Color
        //{
        //    get
        //    {
        //        return _color;
        //    }
        //    set
        //    {
        //        if (StatusTyp == StatusType.Online)
        //        {
        //            _color = new BrushConverter().ConvertFromString("#00ae00") as SolidColorBrush;
        //        }
        //        else if (StatusTyp == StatusType.Offline)
        //        {
        //            _color = new SolidColorBrush(Colors.Red);
        //        }
        //        else
        //        {
        //            _color = new SolidColorBrush(Colors.Orange);
        //        }

        //        OnPropertyChanged("Color");
        //    }
        //}

        //private Brush _colorType;
        //public Brush ColorType
        //{
        //    get
        //    {
        //        return _colorType;
        //    }
        //    set
        //    {
        //        if (TypeChat == ChatType.Team)
        //        {
        //            _colorType = new SolidColorBrush(Colors.DarkViolet);
        //        }
        //        else if (TypeChat == ChatType.Klienten)
        //        {
        //            _colorType = new SolidColorBrush(Colors.Blue);
        //        }
        //        else
        //        {
        //            _colorType = new SolidColorBrush(Colors.Green);
        //        }

        //        OnPropertyChanged("ColorType");
        //    }
        //}
        //public CompactCustomerDC Customer { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }      
    }
}
