using System.ComponentModel;
using System.Windows.Media;

namespace BS.Shared.DataContracts
{
    public class FlatSupportConceptTreeNodeDC : INotifyPropertyChanged
    {
        private string _CustomerWarning;

        private string _EmployeeWarning;

        private bool _IsCustomerWarningActive;

        private bool _IsEmployeeWarningActive;

        public event PropertyChangedEventHandler PropertyChanged;

        public string CostBearerName
        {
            get
            {
                if (this.SupportConceptTreeNodeDC == null)
                {
                    return string.Empty;
                }

                if (this.SupportConceptTreeNodeDC.CostBearer != null)
                {
                    return this.SupportConceptTreeNodeDC.CostBearer.ToString();
                }

                return string.Empty;
            }
        }

        public string CustomerName
        {
            get
            {
                if (this.SupportConceptTreeNodeDC == null)
                {
                    return "<Kein Hilfeplan ausgewählt>";
                }

                if (this.SupportConceptTreeNodeDC.Customer != null)
                {
                    return this.SupportConceptTreeNodeDC.Customer.ToString();
                }

                return string.Empty;
            }
        }

        public string CustomerWarning
        {
            get
            {
                return this._CustomerWarning;
            }

            set
            {
                this._CustomerWarning = value;
                this.RaisePropertyChanged("CustomerWarning");
            }
        }

        public string EmployeeWarning
        {
            get
            {
                return this._EmployeeWarning;
            }

            set
            {
                this._EmployeeWarning = value;
                this.RaisePropertyChanged("EmployeeWarning");
            }
        }

        public bool ExpiresIn3MonthOrLess
        {
            get
            {
                if (this.SupportConceptTreeNodeDC != null)
                {
                    return this.SupportConceptTreeNodeDC.ExpiresIn3MonthOrLess;
                }

                return false;
            }
        }

        public bool IsAboutToExpire
        {
            get
            {
                if (this.SupportConceptTreeNodeDC != null)
                {
                    return this.SupportConceptTreeNodeDC.IsAboutToExpire;
                }

                return false;
            }
        }

        public bool IsCustomerWarningActive
        {
            get
            {
                return this._IsCustomerWarningActive;
            }

            set
            {
                this._IsCustomerWarningActive = value;
                this.RaisePropertyChanged("IsCustomerWarningActive");
            }
        }

        public bool IsEmployeeWarningActive
        {
            get
            {
                return this._IsEmployeeWarningActive;
            }

            set
            {
                this._IsEmployeeWarningActive = value;
                this.RaisePropertyChanged("IsEmployeeWarningActive");
            }
        }

        public Brush NodeForegroundBrush
        {
            get
            {
                if (this.IsAboutToExpire)
                {
                    return Brushes.Red;
                }
                else if (this.ExpiresIn3MonthOrLess)
                {
                    return Brushes.Yellow;
                }
                else
                {
                    return new SolidColorBrush(Color.FromRgb(160, 160, 160));
                }
            }
        }

        public string SupportConceptName
        {
            get
            {
                if (this.SupportConceptTreeNodeDC == null)
                {
                    return string.Empty;
                }

                // if (this.SupportConceptTreeNodeDC.SupportConcept != null)
                // return "Plan vom " + this.SupportConceptTreeNodeDC.SupportConcept.ToString();
                if (this.SupportConceptTreeNodeDC.SupportConceptCostBearerRelDC != null)
                {
                    return "Plan vom " + this.SupportConceptTreeNodeDC.SupportConceptCostBearerRelDC.DateRangeString;
                }

                return string.Empty;
            }
        }

        public SupportConceptTreeNodeDC SupportConceptTreeNodeDC { get; set; }

        protected void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if (propertyChanged != null)
            {
                propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}