using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

using EVE.EVEObjects;
using EVE.EVEObjects.EVEObjectComponents;

namespace EVE.EVEScene {
	public class EVESceneGraph {

        protected EVENodeCollection myNodes;

        public void AddObject(int uID , EVEObject newObject)
        {
            EVEObjectNode newNode = new EVEObjectNode(uID,newObject);
            myNodes.Add(uID, newNode);
        }

		public EVESceneGraph() {
            myNodes = new EVENodeCollection();
		}

        public EVENode getNode(int nodeNo)
        {
            return myNodes[nodeNo];
        }

        public EVEObjectNode getObjectNode(int nodeNo)
        {
            return (EVEObjectNode)myNodes[nodeNo];
        }

        public void LoadGraphicsContent(GraphicsDevice myDevice, ContentManager myLoader)
        {
            foreach (EVENode node in myNodes.Values)
            {
                node.LoadGraphicsContent(myDevice, myLoader);
            }
        }

        public void Update()
        {
            foreach (EVENode node in myNodes.Values)
            {
                node.Update();
            }
        }

        public void Draw(GraphicsDevice myDevice)
        {
            foreach (EVENode node in myNodes.Values)
            {
                node.Draw(myDevice);
            }
        }
	}

	public class EVEObjectNode : EVENode {
		public EVEObject myObject;

		public EVEObjectNode(int uID,EVEObject newObject) : base(uID) {
			myObject = newObject;
		}

		public override void Draw(GraphicsDevice myDevice) {
			myObject.Draw(myDevice);
		}

		public override void LoadGraphicsContent(GraphicsDevice myDevice, ContentManager myLoader) {
			if(myObject is IEVELoadable) {
				((IEVELoadable)myObject).LoadGraphicsContent(myDevice, myLoader);
			}
		}
	}

	public class EVENode {
        private int uniqueID;
        public int uID { get { return uniqueID; } } 

		public EVENode(int uID) 
        {
            uniqueID = uID;
		}


		public virtual void LoadGraphicsContent(GraphicsDevice myDevice, ContentManager myLoader)
        {           
		}

        public virtual void Update()
        {
        }            

		public virtual void Draw(GraphicsDevice myDevice)
        {
        }
	}
	public class EVENodeCollection : Dictionary<int,EVENode> { }
}