using UnityEditor;

namespace XGame.Editor.Build
{
    [BuildCommand((uint)BuildCommandPriority.SwitchPlatform)]
    internal class CmdSwitchPlatform : BaseBuildCommand, ICommandExecuterAsync
    {
        public void Execute()
        {
            BuildLog.Log("CmdSwitchPlatform Execute.");
            var target = Context.config.target;
            if (EditorUserBuildSettings.activeBuildTarget != target)
            {
                BuildCompileEvent.RegistEvent(Context);
                var targetGroup = target.ToTargetGroup();
                BuildLog.Log($"Switch Platform Current:{EditorUserBuildSettings.activeBuildTarget} Target:{target}");
                EditorUserBuildSettings.SwitchActiveBuildTarget(targetGroup, target);
            }
            else
            {
                this.Completed();
            }
        }
    }
}
