using System.Linq;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using HarmonyLib.Tools;

// To make harmony work I had to hack t he game apart a little
// The game by default does not like harmony mods and unpatches all methods when running
// So to stop it from doing this remove calls to:
// System.Void XRL.ModInfo::UnapplyHarmonyPatches()
namespace CykaOfQud {
	[BepInPlugin(pluginGuid, pluginName, pluginVersion)]
	public class Main : BaseUnityPlugin {
		private const string pluginGuid = "CykaOfQud";
		private const string pluginName = "CykaOfQud";
		private const string pluginVersion = "1.0.0";

		public static ConfigEntry<float> xpMultiplier;
		public static ConfigEntry<float> hitpointsPerLevelMultiplier;
		public static ConfigEntry<float> skillPointsPerLevelMultiplier;
		public static ConfigEntry<float> mutationPointsPerLevelMultiplier;
		public static ConfigEntry<float> attributePointsPerLevelMultiplier;
		public static ConfigEntry<float> attributeBonusPerLevelMultiplier;
		public static ConfigEntry<float> disassemblyBonusMultiplier;

		public static ConfigEntry<float> reverseEngineerChanceMultiplier;
		public static ConfigEntry<int> reverseEngineerChanceAdditional;

		public static ConfigEntry<bool> debugMode;

		public void Awake() {
			xpMultiplier = Config.Bind("General", "XP Multiplier", 4f, new ConfigDescription("XP Multiplier"));
			hitpointsPerLevelMultiplier = Config.Bind("General", "Hitpoints Per Level Multiplier", 1f,
				new ConfigDescription("Hitpoints Per Level Multiplier"));
			skillPointsPerLevelMultiplier = Config.Bind("General", "Skill Points Per Level Multiplier", 1f,
				new ConfigDescription("Skill Points Per Level Multiplier"));
			mutationPointsPerLevelMultiplier = Config.Bind("General", "Mutation Points Per Level Multiplier", 1f,
				new ConfigDescription("Mutation Points Per Level Multiplier"));
			attributePointsPerLevelMultiplier = Config.Bind("General", "Attribute Points Per Level Multiplier", 1f,
				new ConfigDescription("Attribute Points Per Level Multiplier"));
			attributeBonusPerLevelMultiplier = Config.Bind("General", "Attribute Bonus Per Level Multiplier", 1f,
				new ConfigDescription("Attribute Bonus Per Level Multiplier"));
			disassemblyBonusMultiplier = Config.Bind("General", "Disassembly Bonus Multiplier", 1f,
				new ConfigDescription("Disassembly Bonus Multiplier"));
			reverseEngineerChanceMultiplier = Config.Bind("General", "Reverse Engineer Chance Multiplier", 1f,
				new ConfigDescription("Reverse Engineer Chance Multiplier"));
			reverseEngineerChanceAdditional = Config.Bind("General", "Reverse Engineer Chance Additional", 0,
				new ConfigDescription("Reverse Engineer Chance Additional"));

			debugMode = Config.Bind("General", "Debug Mode", false, new ConfigDescription("Debug Mode"));

			Logger.LogInfo("Cyka mod loaded");
			HarmonyFileLog.Enabled = true;
			Harmony harmony = new Harmony(pluginGuid);
			harmony.PatchAll();
			var originalMethods = harmony.GetPatchedMethods();
			Logger.LogInfo("Patched " + originalMethods.Count() + " methods");
			foreach (var method in originalMethods) {
				Logger.LogInfo("Patched " + method.Name);
			}
		}
	}
}