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

using HarmonyLib;
using Svelto.ECS;
using RobocraftX.Common;
using RobocraftX.StateSync;

using GamecraftModdingAPI.Utility;

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

		public static readonly GameStateBuildEmitterEngine buildEngine = new GameStateBuildEmitterEngine();

		public static readonly GameStateSimulationEmitterEngine simEngine = new GameStateSimulationEmitterEngine();
        
		public static void Postfix()
        {
			//stateSyncReg.buildModeInitializationEngines.Add(buildEngine);
			//stateSyncReg.simulationModeInitializationEngines.Add(simEngine);
			//enginesRoot.AddEngine(buildEngine);
			//enginesRoot.AddEngine(simEngine);
			buildEngine.EmitIfBuildMode();
			simEngine.EmitIfSimMode();
        }

		[HarmonyTargetMethod]
		public static MethodBase TargetMethod(Harmony harmonyInstance)
		{
			return AccessTools.Method(AccessTools.TypeByName("RobocraftX.StateSync.GameHostTransitionDeterministicGroupEngine"), "EndTransition");
				              //.MakeGenericMethod(typeof(CosmeticEnginesSequenceBuildOrder), typeof(CosmeticEnginesSequenceSimOrder), typeof(DeterministicToCosmeticSyncBuildOrder), typeof(DeterministicToCosmeticSyncSimOrder));
		}
    }
}