using System;
using System.Diagnostics;
using HarmonyLib;
using HutongGames.PlayMaker.Actions;
using UnityEngine;

namespace DavesPhatStore {
	[HarmonyPatch]
	public class BuilderDecoration {
		// private static Transform lastValidPosition = null;

		// [HarmonyPostfix]
		// [HarmonyPatch(typeof(Builder_Decoration), "Update")]
		// public static void Update(Builder_Decoration __instance) {
		// 	var instanceT = Traverse.Create(__instance);
		// 	var dummyOBJ = instanceT.Field("dummyOBJ").GetValue<GameObject>();
		// 	if (dummyOBJ == null) {
		// 		Console.WriteLine("No dummyOBJ");
		// 		return;
		// 	}

		// 	var canPlace = instanceT.Field("canPlace").GetValue<bool>();
		// 	if (canPlace) {
		// 		Console.WriteLine($"Can place at {dummyOBJ.transform}");
		// 		lastValidPosition = dummyOBJ.transform;
		// 	} else {
		// 		Console.WriteLine($"Cannot place, reverting to {lastValidPosition.position}");
		// 		dummyOBJ.transform.position = lastValidPosition.position;
		// 	}
		// }

		// [HarmonyPrefix]
		// [HarmonyPatch(typeof(NetworkSpawner), "UserCode_CmdSpawn__Int32__Vector3__Vector3")]
		// public static void UserCode_CmdSpawn__Int32__Vector3__Vector3(ref int prefabID, ref Vector3 pos, ref Vector3 rot) {
		// 	Console.WriteLine(new StackTrace().ToString());
		// 	Console.WriteLine($"Spawning {prefabID} at {pos.ToString()} with rot {rot.ToString()}");
		// }

		// [HarmonyPrefix]
		// [HarmonyPatch(typeof(NetworkSpawner), "CmdSpawn")]
		// public static void CmdSpawn(ref int prefabID, ref Vector3 pos, ref Vector3 rot) {
		// 	Console.WriteLine(new StackTrace().ToString());
		// 	Console.WriteLine($"Spawning {prefabID} at {pos.ToString()} with rot {rot.ToString()}");
		// }

		// [HarmonyPrefix]
		// [HarmonyPatch(typeof(CallMethod), "DoMethodCall")]
		// public static void DoMethodCall(CallMethod __instance) {
		// 	var traverse = Traverse.Create(__instance);
		// 	Console.WriteLine($"DoMethodCall cachedMethodInfo: {traverse.Field("cachedMethodInfo").GetValue()}");
		// 	Console.WriteLine($"DoMethodCall cachedBehaviour: {traverse.Field("cachedBehaviour").GetValue()}");
		// 	Console.WriteLine($"DoMethodCall parameters: {traverse.Field("parameters").GetValue()}");
		// 	Console.WriteLine(new StackTrace().ToString());
		// }

		// [HarmonyPostfix]
		// [HarmonyPatch(typeof(CallMethod), "DoMethodCall")]
		// public static void PostDoMethodCall(CallMethod __instance) {
		// 	var traverse = Traverse.Create(__instance);
		// 	Console.WriteLine($"DoMethodCall cachedMethodInfo: {traverse.Field("cachedMethodInfo").GetValue()}");
		// 	Console.WriteLine($"DoMethodCall cachedBehaviour: {traverse.Field("cachedBehaviour").GetValue()}");
		// 	Console.WriteLine($"DoMethodCall parameters: {traverse.Field("parameters").GetValue()}");
		// 	Console.WriteLine(new StackTrace().ToString());
		// }
	}
}