using System;
using System.Collections.Generic;
using System.Text;
using CommonLang.Property;
using CommonAI.Zone.Attributes;
using CommonAI.Zone.ZoneEditor;
using CommonLang.Formula;

using CommonAI.Zone.Instance;
using CommonAI.RTS; using CommonLang.Vector;
using CommonLang;
using CommonAI.Zone.EventTrigger;

namespace CommonAI.Zone.ZoneEditor.EventTrigger
{
    public static class AbstractValueTypeMap
    {
        private static TypeDescAttribute[] types = new TypeDescAttribute[]{
                new TypeDescAttribute(typeof(StringValue)),
                new TypeDescAttribute(typeof(IntegerValue)),
                new TypeDescAttribute(typeof(RealValue)),
                new TypeDescAttribute(typeof(BooleanValue)),
                new TypeDescAttribute(typeof(UnitValue)),
                new TypeDescAttribute(typeof(ItemValue)),
                new TypeDescAttribute(typeof(FlagValue)),
                new TypeDescAttribute(typeof(PositionValue)),
                new TypeDescAttribute(typeof(ItemTemplateValue)),
                new TypeDescAttribute(typeof(BuffTemplateValue)),
            };

        public static TypeDescAttribute[] DescTypes
        {
            get { return types; }
        }

        public static TypeDescAttribute GetBaseValueType(Type type)
        {
            foreach (TypeDescAttribute baseType in types)
            {
                if (baseType.DataType.IsAssignableFrom(type))
                {
                    return baseType;
                }
            }
            return null;
        }

        public static object MakeDefault(Type desc)
        {
            if (desc.Equals(typeof(StringValue)))
                return new StringValue.VALUE();
            if (desc.Equals(typeof(IntegerValue)))
                return new IntegerValue.VALUE();
            if (desc.Equals(typeof(RealValue)))
                return new RealValue.VALUE();
            if (desc.Equals(typeof(BooleanValue)))
                return new BooleanValue.VALUE();

            if (desc.Equals(typeof(UnitValue)))
                return new UnitValue.NA();
            if (desc.Equals(typeof(ItemValue)))
                return new ItemValue.NA();
            if (desc.Equals(typeof(FlagValue)))
                return new FlagValue.NA();
            if (desc.Equals(typeof(PositionValue)))
                return new PositionValue.VALUE();
            if (desc.Equals(typeof(ItemTemplateValue)))
                return new ItemTemplateValue.Template();

            return null;
        }
    }

    //-------------------------------------------------------------------------------------


}