/*
 *Copyright(C) 2023 by Chief All rights reserved.
 *Unity版本：2023.2.5f1c1 
 *作者:Chief  
 *创建日期: 2024-01-19 
 *模块说明：通用命令辅助
 *版本: 1.0
*/

using System;

namespace Aster.AsterTask
{
    /// <summary>
    /// 命令辅助
    /// </summary>
    public static class AsterCommandUtils
    {

        private static AsterCommandRunner m_Runner;

        public static void CreateCoomandRunner()
        {
            m_Runner = AsterCommandRunner.Create();
        }

        public static void DestroyCoomandRunner()
        {
            AsterCommandRunner.Release();
        }

        public static void Enqueue(this I_AsterCommand cmd)
        {
            if (m_Runner == null)
            {
                Logger.LogError($"没有初始化命令！需要先运行 AsterCommandUtils.CreateCoomandRunner()");
                return;
            }

            m_Runner.Enqueue(cmd);
        }


        public static void MainthreadCallBack(Action callback, bool slow = false, bool fast = false)
        {
            if (callback == null)
                return;

            var cmd = AsterMainthreadCommand.Get();
            cmd.CallBack = callback;
            cmd.SlowCmd = slow;
            cmd.FascCmd = fast;
            cmd.Enqueue();
        }

        public static void MainthreadCallBack(Action<object> callback, object param, bool slow = false, bool fast = false)
        {
            if (callback == null)
                return;

            var cmd = AsterMainthreadCommandWithParam.Get();
            cmd.CallBack = callback;
            cmd.param = param;
            cmd.SlowCmd = slow;
            cmd.FascCmd = fast;
            cmd.Enqueue();
        }

    }
}