using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace GridViewComboBoxColumn_WPF
{
	/// <summary>
	/// A football club.
	/// </summary>
	public class Club : INotifyPropertyChanged
	{
		public event PropertyChangedEventHandler PropertyChanged;

		private string name;
		private DateTime established;
		private int stadiumCapacity;
		private ObservableCollection<Player> players;
		private int id;
		public int ID
		{
			get { return this.id; }
			set
			{
				if (value != this.id)
				{
					this.id = value;
					this.OnPropertyChanged("ID");
				}
			}
		}


		public string Name
		{
			get { return this.name; }
			set
			{
				if (value != this.name)
				{
					this.name = value;
					this.OnPropertyChanged("Name");
				}
			}
		}

		public DateTime Established
		{
			get { return this.established; }
			set
			{
				if (value != this.established)
				{
					this.established = value;
					this.OnPropertyChanged("Established");
				}
			}
		}

		public int StadiumCapacity
		{
			get { return this.stadiumCapacity; }
			set
			{
				if (value != this.stadiumCapacity)
				{
					this.stadiumCapacity = value;
					this.OnPropertyChanged("StadiumCapacity");
				}
			}
		}

		public ObservableCollection<Player> Players
		{
			get
			{
				if (null == this.players)
				{
					this.players = new ObservableCollection<Player>();
				}

				return this.players;
			}
		}

		public Club()
		{

		}

		public Club(string name, DateTime established, int stadiumCapacity, int id)
		{
			this.name = name;
			this.established = established;
			this.stadiumCapacity = stadiumCapacity;
			this.id = id;
		}

		public Club(string name, DateTime established, int stadiumCapacity, ObservableCollection<Player> players, int id)
			: this(name, established, stadiumCapacity, id)
		{
			this.players = players;
		}

		protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
		{
			PropertyChangedEventHandler handler = this.PropertyChanged;
			if (handler != null)
			{
				handler(this, args);
			}
		}

		private void OnPropertyChanged(string propertyName)
		{
			this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
		}

		public override string ToString()
		{
			return this.Name;
		}

		public static ObservableCollection<Club> GetClubs()
		{
			ObservableCollection<Club> clubs = new ObservableCollection<Club>();
			Club club;

			// Liverpool
			club = new Club("Liverpool", new DateTime(1892, 1, 1), 45362, 1);
			club.Players.Add(new Player("Pepe Reina", 25, Position.GK, "Spain", 1, 3));
			clubs.Add(club);

			// Manchester Utd.
			club = new Club("Manchester Utd.", new DateTime(1878, 1, 1), 76212, 2);
			club.Players.Add(new Player("Edwin van der Sar", 1, Position.GK, "Netherlands", 2, 4));
			clubs.Add(club);

			// Chelsea
			club = new Club("Chelsea", new DateTime(1905, 1, 1), 42055, 3);
			club.Players.Add(new Player("Petr Čech", 1, Position.GK, "Czech Republic", 3, 2));
			clubs.Add(club);

			// Arsenal
			club = new Club("Arsenal", new DateTime(1886, 1, 1), 60355, 4);
			club.Players.Add(new Player("Manuel Almunia", 1, Position.GK, "Spain", 4, 1));
			clubs.Add(club);

			return clubs;
		}

		public static ObservableCollection<Club> GetClubs2()
		{
			ObservableCollection<Club> clubs = new ObservableCollection<Club>();
			Club club;

			// Liverpool
			club = new Club("Liverpool2", new DateTime(1892, 1, 1), 45362, 1);
			club.Players.Add(new Player("Pepe Reina2", 25, Position.GK, "Spain", 1, 3));
			clubs.Add(club);

			// Manchester Utd.
			club = new Club("Manchester Utd.2", new DateTime(1878, 1, 1), 76212, 2);
			club.Players.Add(new Player("Edwin van der Sar2", 1, Position.GK, "Netherlands", 2, 4));
			clubs.Add(club);

			// Chelsea
			club = new Club("Chelsea2", new DateTime(1905, 1, 1), 42055, 3);
			club.Players.Add(new Player("Petr Čech2", 1, Position.GK, "Czech Republic", 3, 2));
			clubs.Add(club);

			// Arsenal
			club = new Club("Arsenal2", new DateTime(1886, 1, 1), 60355, 4);
			club.Players.Add(new Player("Manuel Almunia2", 1, Position.GK, "Spain", 4, 1));
			clubs.Add(club);

			return clubs;
		}

	}
}
