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

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

		private string name;
		private DateTime established;
		private int stadiumCapacity;
		private int playerID;
		private ObservableCollection<Player> players;

		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 int PlayerID
		{
			get { return this.playerID; }
			set
			{
				if (value != this.playerID)
				{
					this.playerID = value;
					this.OnPropertyChanged("PlayerID");
				}
			}
		}

		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 playerID)
		{
			this.name = name;
			this.established = established;
			this.stadiumCapacity = stadiumCapacity;
			this.playerID = playerID;
		}

		public Club(string name, DateTime established, int stadiumCapacity, int playerID, ObservableCollection<Player> players)
			: this(name, established, stadiumCapacity, playerID)
		{
			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));
			club.Players.Add(new Player("Jamie Carragher", 23));
			club.Players.Add(new Player("Steven Gerrard", 8));
			club.Players.Add(new Player("Fernando Torres", 9));
			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));
			club.Players.Add(new Player("Rio Ferdinand", 2));
			club.Players.Add(new Player("Ryan Giggs", 3));
			club.Players.Add(new Player("Wayne Rooney", 4));
			clubs.Add(club);

			// Chelsea
			club = new Club("Chelsea", new DateTime(1905, 1, 1), 42055, 3);
			club.Players.Add(new Player("Petr Čech", 5));
			club.Players.Add(new Player("John Terry", 6));
			club.Players.Add(new Player("Frank Lampard", 8));
			club.Players.Add(new Player("Nicolas Anelka", 9));
			clubs.Add(club);

			// Arsenal
			club = new Club("Arsenal", new DateTime(1886, 1, 1), 60355, 4);
			club.Players.Add(new Player("Manuel Almunia", 7));
			club.Players.Add(new Player("Gaël Clichy", 10));
			club.Players.Add(new Player("Cesc Fàbregas", 12));
			club.Players.Add(new Player("Robin van Persie", 11));
			clubs.Add(club);

			return clubs;
		}
	}
}
