using System;

namespace XGame.Editor.Build
{
    internal static class CmdFactory
    {
        public static IBuildCommand Create(BuildContext context)
        {
            var type = GetFirstType(context);
            if (type != null)
            {
                // 还有Cmd接着执行
                var command = Activator.CreateInstance(type) as IBuildCommand;
                if (command is IBuildContextAdapter adapter)
                {
                    adapter.Context = context;
                }
                return command;
            }
            return null;
        }
        private static Type GetFirstType(BuildContext context)
        {
            var cmdTypeNames = context.cmdTypeNames;
            if (cmdTypeNames != null && cmdTypeNames.Count > 0)
            {
                var typeName = cmdTypeNames[0];
                var type = Type.GetType(typeName);
                cmdTypeNames.RemoveAt(0);
                return type;
            }
            return null;
        }
    }
}
