using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text;

namespace TabKey_InsertRow
{
	public class Person : global::System.ComponentModel.INotifyPropertyChanged
	{
		#region FirstName (INotifyPropertyChanged Property)
		private string _firstName;

		public string FirstName
		{
			get
			{
				return _firstName;
			}
			set
			{
				_firstName = value;
				RaisePropertyChanged("FirstName");
			}
		}

		#endregion
		#region LastName (INotifyPropertyChanged Property)
		private string _lastName;

		public string LastName
		{
			get
			{
				return _lastName;
			}
			set
			{
				_lastName = value;
				RaisePropertyChanged("LastName");
			}
		}

		#endregion
		#region Email (INotifyPropertyChanged Property)
		private string _email;

		public string Email
		{
			get
			{
				return _email;
			}
			set
			{
				_email = value;
				RaisePropertyChanged("Email");
			}
		}

		#endregion
		#region Age (INotifyPropertyChanged Property)
		private int _age;

		public int Age
		{
			get
			{
				return _age;
			}
			set
			{
				_age = value;
				RaisePropertyChanged("Age");
			}
		}

		#endregion
		#region BirthDay (INotifyPropertyChanged Property)
		private DateTime _birthday;

		public DateTime BirthDay
		{
			get
			{
				return _birthday;
			}
			set
			{
				_birthday = value;
				RaisePropertyChanged("BirthDay");
			}
		}

		#endregion
		#region Gender (INotifyPropertyChanged Property)
		private Genders _gender;

		public Genders Gender
		{
			get
			{
				return _gender;
			}
			set
			{
				_gender = value;
				RaisePropertyChanged("Gender");
			}
		}

		#endregion

		public static global::System.Collections.ObjectModel.ObservableCollection<Person> GetPeople()
		{
			global::System.Collections.ObjectModel.ObservableCollection<Person> source = new global::System.Collections.ObjectModel.ObservableCollection<Person>();

			source.Add(new Person("Jack", "Sparrow", 40, Genders.Male));
			source.Add(new Person("Hulk", "Hulk", 35, Genders.Male));
			source.Add(new Person("Cat", "Woman", 24, Genders.Female));
			source.Add(new Person("Frodo", "Baggins", 20, Genders.Male));
			source.Add(new Person("Luke", "Skywalker", 28, Genders.Male));

			return source;
		}

		public static global::System.Collections.ObjectModel.ObservableCollection<Person> GetPeople(int number)
		{
			global::System.Collections.ObjectModel.ObservableCollection<Person> source = new global::System.Collections.ObjectModel.ObservableCollection<Person>();

			for (int i = 0; i < number; i++)
			{
				int age = new Random(i).Next(10, 70);
				source.Add(new Person(RandomString(5), RandomString(7), age, age % 2 == 0 ? Genders.Male : Genders.Female));
			}
			return source;
		}

		public Person()
		{
			this.FirstName = "New First Name";
			this.LastName = "New Last Name";
			this.Age = 0;
			this.Email = "New Email Address";
			this.BirthDay = DateTime.Now;
		}

		public Person(string firstName, string lastName)
		{
			this.FirstName = firstName;
			this.LastName = lastName;
			this.Email = firstName[0] + lastName + "email.com";
		}

		public Person(string firstName, string lastName, int age)
		{
			this.FirstName = firstName;
			this.LastName = lastName;
			this.Email = firstName[0] + lastName + "email.com";
			this.Age = age;
			this.BirthDay = DateTime.Now.AddYears(-age).AddDays(new Random().Next(0, 100));
		}

		public Person(string firstName, string lastName, int age, Genders gender)
		{
			this.FirstName = firstName;
			this.LastName = lastName;
			this.Email = firstName[0] + lastName + "email.com";
			this.Age = age;
			this.BirthDay = DateTime.Now.AddYears(-age).AddDays(new Random().Next(0, 100));
			this.Gender = gender;
		}		

		#region INotifyPropertyChanged values

		public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

		protected void RaisePropertyChanged(string propertyName)
		{
			var handler = PropertyChanged;
			if (handler != null)
			{
				handler(this, new global::System.ComponentModel.PropertyChangedEventArgs(propertyName));
			}
		}

		#endregion

		public enum Genders
		{
			Male,
			Female
		}

		private static string RandomString(int size)
		{
			StringBuilder builder = new StringBuilder();
			Random seed = new Random((int) DateTime.Now.Millisecond);
			System.Threading.Thread.Sleep(1);
			Random random = new Random(seed.Next(0, 1000));
			char ch;
			for (int i = 0; i < size; i++)
			{
				ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
				builder.Append(ch);
			}
			return builder.ToString();
		}
	}
}
