using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

using Harmony;
using Svelto.ECS;
using RobocraftX.StateSync;

using GamecraftModdingAPI.Utility;

namespace GamecraftModdingAPI.Events
{
    /// <summary>
    /// Patch of RobocraftX.StateSync.DeterministicStepCompositionRoot.ComposeEnginesGroups(...)
    /// </summary>
	[HarmonyPatch(typeof(DeterministicStepCompositionRoot), "ComposeEnginesGroups")]
	//[HarmonyPatch]
    class DeterministicStepComposeEngineGroupsPatch
    {

		public static readonly GameStateBuildEmitterEngine buildEngine = new GameStateBuildEmitterEngine();

		public static readonly GameStateSimulationEmitterEngine simEngine = new GameStateSimulationEmitterEngine();
        
        public static void Prefix(ref StateSyncRegistrationHelper stateSyncReg)
        {
			stateSyncReg.buildModeInitializationEngines.Add(buildEngine);
			stateSyncReg.simulationModeInitializationEngines.Add(simEngine);
        }

		public static MethodBase NopeTargetMethod()
        {
			return typeof(DeterministicStepCompositionRoot).GetMethods().First(m => m.Name == "ComposeEnginesGroups")
                .MakeGenericMethod(typeof(object));
        }
    }
}