// -----------------------------------------------------------------------
// <copyright file="MySource.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace AsyncDigrams
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using Telerik.Windows.Diagrams.Core;
	using System.Collections.ObjectModel;

	/// <summary>
	/// TODO: Update summary.
	/// </summary>
	public class MySource : IObservableGraphSource
	{
		private ObservableCollection<MyLink> links;
		private ObservableCollection<MyNode> nodes;

		public MySource()
		{
			this.links = new ObservableCollection<MyLink>();
			this.nodes = new ObservableCollection<MyNode>();

			for (int i = 0; i < 3; i++)
			{
				this.AddNode(new MyNode() { Content = "Shape " + i });
			}

			this.AddLink(new MyLink() { Source = this.nodes[0], Target = this.nodes[1] });
			this.AddLink(new MyLink() { Source = this.nodes[1], Target = this.nodes[2] });
		}

		public System.Collections.IEnumerable Items
		{
			get { return this.nodes; }
		}

		public IEnumerable<ILink> Links
		{
			get { return this.links; }
		}

		public void AddLink(ILink link)
		{
			this.links.Add(link as MyLink);
		}

		public void AddNode(object node)
		{
			this.nodes.Add(node as MyNode);
		}

		public ILink CreateLink(object source, object target)
		{
			var newLink = new MyLink();
			//var newLink = new MyLink() { Source = source, Target = target };

			return newLink;
		}

		public object CreateNode(IShape shape)
		{
			return new MyNode();
		}

		public bool RemoveLink(ILink link)
		{
			return this.links.Remove(link as MyLink);
		}

		public bool RemoveNode(object node)
		{
			return this.nodes.Remove(node as MyNode);
		}
	}
}
