﻿using System;

namespace Universal.Portable.Business
{
    public class Alert : EntityBase
    {
        private string _city;
        private DateTime _createdAt;
        private Incident _incident;
        private string _officer;
        private string _state;
        private string _street;

        public string City
        {
            get { return _city; }
            set
            {
                if (value == _city) return;
                _city = value;
                OnPropertyChanged();
            }
        }

        public DateTime CreatedAt
        {
            get { return _createdAt; }
            set
            {
                if (value.Equals(_createdAt)) return;
                _createdAt = value;
                OnPropertyChanged();
            }
        }

        public string Officer
        {
            get { return _officer; }
            set
            {
                if (value == _officer) return;
                _officer = value;
                OnPropertyChanged();
            }
        }

        public string State
        {
            get { return _state; }
            set
            {
                if (value == _state) return;
                _state = value;
                OnPropertyChanged();
            }
        }

        public string Street
        {
            get { return _street; }
            set
            {
                if (value == _street) return;
                _street = value;
                OnPropertyChanged();
            }
        }

        public Incident Incident
        {
            get { return _incident; }
            set
            {
                if (value == _incident) return;
                _incident = value;
                OnPropertyChanged();
            }
        }

        public override string this[string columnName]
        {
            get
            {
                string error = null;
                switch (columnName)
                {
                    case "Officer":
                    {
                        if (string.IsNullOrEmpty(_officer))
                            error = "Officer name is required";
                        break;
                    }

                    case "Street":
                    {
                        if (string.IsNullOrEmpty(_street))
                            error = "Street name is required";
                        break;
                    }
                    case "City":
                    {
                        if (string.IsNullOrEmpty(_city))
                            error = "City name is required";
                        break;
                    }
                }
                if ((error != null) && !ErrorCollection.ContainsKey(columnName))
                    ErrorCollection.Add(columnName, error);
                if ((error == null) && ErrorCollection.ContainsKey(columnName)) ErrorCollection.Remove(columnName);
                return error;
            }
        }
    }
}