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

namespace RadGridView_MultipleHierarchy
{
	/// <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 ObservableCollection<Club> subClubs;

		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 ObservableCollection<Club> SubClubs
		{
			get
			{
				if (null == this.subClubs)
				{
					this.subClubs = new ObservableCollection<Club>();
				}

				return this.subClubs;
			}
		}

		public Club()
		{

		}

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

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

		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;
			Club subClub;

			// Liverpool
			club = new Club("Liverpool", new DateTime(1892, 1, 1), 45362);
			club.Players.Add(new Player("Pepe Reina", 25, Position.GK, "Spain"));
			club.Players.Add(new Player("Jamie Carragher", 23, Position.DF, "England"));
			club.Players.Add(new Player("Steven Gerrard", 8, Position.MF, "England"));
			club.Players.Add(new Player("Fernando Torres", 9, Position.FW, "Spain"));
			subClub = new Club("Liverpool1", new DateTime(1892, 1, 1), 45362);
			subClub.Players.Add(new Player("Pepe Reina1", 25, Position.GK, "Spain"));
			subClub.Players.Add(new Player("Jamie Carragher1", 23, Position.DF, "England"));
			subClub.Players.Add(new Player("Steven Gerrard1", 8, Position.MF, "England"));
			subClub.Players.Add(new Player("Fernando Torres1", 9, Position.FW, "Spain"));
			club.SubClubs.Add(subClub);
			clubs.Add(club);

			// Manchester Utd.
			club = new Club("Manchester Utd.", new DateTime(1878, 1, 1), 76212);
			club.Players.Add(new Player("Edwin van der Sar", 1, Position.GK, "Netherlands"));
			club.Players.Add(new Player("Rio Ferdinand", 5, Position.DF, "England"));
			club.Players.Add(new Player("Ryan Giggs", 11, Position.MF, "Wales"));
			club.Players.Add(new Player("Wayne Rooney", 10, Position.FW, "England"));

			subClub = new Club("Manchester Utd.1", new DateTime(1878, 1, 1), 76212);
			subClub.Players.Add(new Player("Edwin van der Sar1", 1, Position.GK, "Netherlands"));
			subClub.Players.Add(new Player("Rio Ferdinand1", 5, Position.DF, "England"));
			subClub.Players.Add(new Player("Ryan Giggs1", 11, Position.MF, "Wales"));
			subClub.Players.Add(new Player("Wayne Rooney1", 10, Position.FW, "England"));
			club.SubClubs.Add(subClub);
			clubs.Add(club);

			// Chelsea
			club = new Club("Chelsea", new DateTime(1905, 1, 1), 42055);
			club.Players.Add(new Player("Petr Čech", 1, Position.GK, "Czech Republic"));
			club.Players.Add(new Player("John Terry", 26, Position.DF, "England"));
			club.Players.Add(new Player("Frank Lampard", 8, Position.MF, "England"));
			club.Players.Add(new Player("Nicolas Anelka", 39, Position.FW, "France"));
			subClub = new Club("Chelsea1", new DateTime(1905, 1, 1), 42055);
			subClub.Players.Add(new Player("Petr Čech1", 1, Position.GK, "Czech Republic"));
			subClub.Players.Add(new Player("John Terry1", 26, Position.DF, "England"));
			subClub.Players.Add(new Player("Frank Lampard1", 8, Position.MF, "England"));
			subClub.Players.Add(new Player("Nicolas Anelka1", 39, Position.FW, "France"));
			club.SubClubs.Add(subClub);
			clubs.Add(club);

			// Arsenal
			club = new Club("Arsenal", new DateTime(1886, 1, 1), 60355);
			club.Players.Add(new Player("Manuel Almunia", 1, Position.GK, "Spain"));
			club.Players.Add(new Player("Gaël Clichy", 22, Position.DF, "France"));
			club.Players.Add(new Player("Cesc Fàbregas", 4, Position.MF, "Spain"));
			club.Players.Add(new Player("Robin van Persie", 11, Position.FW, "Netherlands"));
			subClub = new Club("Arsena1l", new DateTime(1886, 1, 1), 60355);
			subClub.Players.Add(new Player("Manuel Almunia1", 1, Position.GK, "Spain"));
			subClub.Players.Add(new Player("Gaël Clichy1", 22, Position.DF, "France"));
			subClub.Players.Add(new Player("Cesc Fàbregas1", 4, Position.MF, "Spain"));
			subClub.Players.Add(new Player("Robin van Persie1", 11, Position.FW, "Netherlands"));
			club.SubClubs.Add(subClub);
			clubs.Add(club);

			return clubs;
		}
	}
}
