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

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

		private string name;		
		private int countryID;
		private ObservableCollection<Player> players;

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

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

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

				return this.players;
			}
		}

		public Club()
		{

		}

		public Club(string name, int countryID)
		{
			this.name = name;
			this.countryID = countryID;
		}

		public Club(string name, int countryID, ObservableCollection<Player> players)
			: this(name, countryID)
		{
			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", 2);
			club.Players.Add(new Player("Pepe Reina", 1));
			club.Players.Add(new Player("Jamie Carragher",  2));
			club.Players.Add(new Player("Steven Gerrard", 2));
			club.Players.Add(new Player("Fernando Torres",  1));
			clubs.Add(club);

			// Manchester Utd.
			club = new Club("Manchester Utd.", 2);
			club.Players.Add(new Player("Edwin van der Sar",  3));
			club.Players.Add(new Player("Rio Ferdinand",  2));
			club.Players.Add(new Player("Ryan Giggs", 5));
			club.Players.Add(new Player("Wayne Rooney",  2));
			clubs.Add(club);

			// Chelsea
			club = new Club("Chelsea", 2);
			club.Players.Add(new Player("Petr Čech",  6));
			club.Players.Add(new Player("John Terry",  2));
			club.Players.Add(new Player("Frank Lampard",  2));
			club.Players.Add(new Player("Nicolas Anelka",  4));
			clubs.Add(club);

			// Arsenal
			club = new Club("Arsenal", 2);
			club.Players.Add(new Player("Manuel Almunia",1));
			club.Players.Add(new Player("Gaël Clichy",  4));
			club.Players.Add(new Player("Cesc Fàbregas",  1));
			club.Players.Add(new Player("Robin van Persie",  3));
			clubs.Add(club);

			return clubs;
		}
	}
}
