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

using EVE.EVERenderer;
using EVE.EVEObjects;

using Microsoft.Xna.Framework;

namespace EVE.EVELogic
{
    public class EVEGlobalManager
    {
        private static EVEUpdateManager Updater;
        private static EVERenderManager Renderer;

        private static List<int> usedID;

        private static int uniqueID = 0;

        public static void prepareManager(EVEUpdateManager u, EVERenderManager r)
        {
            Updater = u;
            Renderer = r;
            usedID = new List<int>();
        }

        public static void registerObject(int uId, EVEUnit unitData, EVEObject renderData)
        {
            Updater.addUnit(uId, unitData);
            Renderer.Scene.AddObject(uId, renderData);
        }

        public static int getUID()
        {
            int nextUID = uniqueID++;
            
            while(usedID.Contains(nextUID))
                nextUID++;

            uniqueID = nextUID;
            usedID.Add(uniqueID);
            return uniqueID;
        }

        public static int currentUID()
        {
            return uniqueID;
        }

        public static void createObject(EVEUnitType uType, String modelName, String shaderName, String texture, Vector3 position, Vector3 color)
        {
            int aID = getUID();

            EVESkybox tSky;
            EVEModel tModel;
            EVEUnit tUnit;

            switch (uType)
            {
                case EVEUnitType.default_Renderable_Physical_nonStatic:
                    tModel = new EVEModel(modelName);
                    tUnit = new EVEUnit(aID);
                    tUnit.isPhysical = true;
                    tUnit.isStatic = false;
                    registerObject(aID, tUnit, tModel);
                    break;
                case EVEUnitType.default_Renderable_Physical_Static:
                    tModel = new EVEModel(modelName);
                    tUnit = new EVEUnit(aID);
                    tUnit.isPhysical = true;
                    tUnit.isStatic = true;
                    registerObject(aID, tUnit, tModel);
                    break;
                case EVEUnitType.default_Renderable_nonPhysical_Static:
                    tModel = new EVEModel(modelName);
                    tUnit = new EVEUnit(aID);
                    tUnit.isPhysical = false;
                    tUnit.isStatic = true;
                    registerObject(aID, tUnit, tModel);
                    break;
            }
        }


    }
}
