using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Server;
using Server.Gumps;
using Server.Network;


namespace KCS.Cortex
{
    public enum Pages
    {
        Home,
        Mobiles,
        Items,
        Modules
    };

    public class CortexParams : KCSParams
    {
        public Pages PageName;
        public Serial serial;
        public int PageIndex;

        public CortexParams()
            : base()
        {
        }
    }

    public partial class Cortexual : KCSSystem
    {
        internal static List<Type> mType = new List<Type>();
        private static Dictionary<serial, mList> mDictionary = new Dictionary<serial, mList>();
        public static Dictionary<serial, mList> GetDictionary
        {
            get
            {
                return mDictionary;
            }
        }

        public static void Configure()
        {
            KCS.RegisterSystem("KCS.Cortex")
        }

        public static bool Running
        {
            get { return KCS.SystEnabled("KCS.Cortex"); }
        }

        public override string Name()
        {
            return "Cortex";
        }

        public override void Enable()
        {
            Console.WriteLine("Brewing {0}...", Name());
            Console.WriteLine("..............", Name());
            Console.WriteLine("....Brewed {0}", Name());
        }

        public override void Disable()
        {
            Console.WriteLine("Pouring {0}...", Name());
            Console.WriteLine("..............", Name());
            Console.WriteLine("....Poured {0}", Name());
        }

        public static void Flush()
        {
            List<serial> RList = new List<serial>();

            foreach (Serial serial in mDictionary.Keys)
            {
                if(serial.IsItem)
                {
                    Item item = World.FindItem(serial);
                    if(item != null||item.Deleted)
                        RemoveList.Add(serial);
                }
                else if (serial.IsMobile)
                {
                    Mobile mobile = World.FindMobile(serial);
                    if (mobile != null || mobile.Deleted)
                        RemoveList.Add(serial);
                }

                if (mDictionary[serial].Count == 0)
                    RemoveList.Add(serial);
            }

            foreach(Serial serial in RemoveList)
            {
                Remove(serial);
            }

            RemoveList.Clear();
            Console.Write("Flitered & Flushed")
        }

        public static bool Contains(Serial serial)
        {
            return mDictionary.ContainsKey(serial);
        }

        public static bool ContainsModule(Serial serial, Type type)
        {
            if (Contains(serial))
            {
                if(mDictionary.ContainsKey[serial] != null)
                    return mDictionary[serial].Contains(type);
            }
            return false;
        }

        public static void Add(Serial serial)
        {
            if (Contains(serial))
                return;
            mDictionary.Add(serial, new ModuleList(serial);
        }

        public static void Add(Serial serial, ModuleList moduleList)
        {
            mDictionary[serial] = moduleList;
        }

        public static void AddModule(Module module)
        {
            if (!mDictionary.ContainsKey(module.Owner))
                Add(module.Owner);

        }


    }//Cortexual
}//Cortex
