using System;
using System.Collections.Generic;
using System.Text;
using Halo3Map.Data;
using System.Windows.Forms;
using System.IO;
using Halo3Map.Tags.Layouts;

namespace Halo3Map.Tags
{
    public class TagHandler
    {

        public enum TagType
        {
            HardCoded,
            Plugin,
        }

        public static H3Tag GetTag(string TagClass, TagType Type)
        {
            H3Tag returnTag = null;

            if (Type == TagType.HardCoded)
                returnTag = GetHardCodedTag(TagClass);
            else
                returnTag = GetPluginTag(TagClass);

            return returnTag;
        }

        private static H3Tag GetHardCodedTag(string TagClass)
        {
            H3Tag returnTag = null;

            switch (TagClass)
            {

                case "bitm":
                    {
                        returnTag = new bitm();
                        break;
                    }
                case "colo":
                    {
                        returnTag = new colo();
                        break;
                    }
                case "hlmt":
                    {
                        returnTag = new hlmt();
                        break;
                    }
                case "perf":
                    {
                        returnTag = new perf();
                        break;
                    }
                case "play":
                    {
                        returnTag = new play();
                        break;
                    }
                case "sbsp":
                    {
                        returnTag = new sbsp();
                        break;
                    }
                case "scnr":
                    {
                        returnTag = new scnr();
                        break;
                    }
                case "sily":
                    {
                        returnTag = new sily();
                        break;
                    }
                case "trak":
                    {
                        returnTag = new trak();
                        break;
                    }
                case "ugh!":
                    {
                        returnTag = new ugh_();
                        break;
                    }
                case "weap":
                    {
                        returnTag = new weap();
                        break;
                    }
                case "zone":
                    {
                        returnTag = new zone();
                        break;
                    }
                    
            }

            return returnTag;
        }

        private static H3Tag GetPluginTag(string TagClass)
        {
            string pluginDir = Application.StartupPath + "\\CSPlugins\\";
            string pluginPath = pluginDir + TagClass + ".cs";

            if (!File.Exists((pluginPath.Replace('<', '_')).Replace('>', '_')))
                return null;

            //return pluginCompiler.CompileTagPlugin(pluginPath);
            return pluginCompiler.CompileTagPlugin((pluginPath.Replace('<', '_')).Replace('>', '_'));
        }

    }
}
