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

namespace Regiments {
    [BepInPlugin(pluginGuid, pluginName, pluginVersion)]
    public class Main : BaseUnityPlugin {
        private const string pluginGuid = "CykaMod";
        private const string pluginName = "CykaMod";
        private const string pluginVersion = "1.0.0";

        public static ConfigEntry<float> SPMultiplier;
        public static ConfigEntry<float> TPMultiplier;
        public static ConfigEntry<float> SupplyAOEMultiplier;
        public static ConfigEntry<float> HQAOEMultiplier;
        public static ConfigEntry<float> SupplyAmountMultiplier;
        public static ConfigEntry<float> FireRateMultiplier;
        public static ConfigEntry<float> AimIntervalMultiplier;
        public static ConfigEntry<float> SupplyRateMultiplier;
        public static ConfigEntry<float> MovementSpeedMultiplier;

        public void Awake() {
            SPMultiplier = Config.Bind("General", "SP Multiplier", 1f,
                new ConfigDescription("SP Multiplier", new AcceptableValueRange<float>(1f, 32f)));
            TPMultiplier = Config.Bind("General", "TP Multiplier", 1f,
                new ConfigDescription("TP Multiplier", new AcceptableValueRange<float>(1f, 32f)));
            SupplyAOEMultiplier = Config.Bind("General", "Supply AOE Multiplier", 1f,
                new ConfigDescription("Supply AOE Multiplier", new AcceptableValueRange<float>(1f, 32f)));
            SupplyAmountMultiplier = Config.Bind("General", "Supply Point Amount Multiplier", 1f,
                new ConfigDescription("Supply Point Amount Multiplier", new AcceptableValueRange<float>(1f, 32f)));
            SupplyRateMultiplier = Config.Bind("General", "The rate at which HP and ammo is resupplied", 1f,
                new ConfigDescription("The rate at which HP and ammo is resupplied", new AcceptableValueRange<float>(1f, 16f)));
            HQAOEMultiplier = Config.Bind("General", "HQ AOE Multiplier", 1f,
                new ConfigDescription("HQ AOE Multiplier", new AcceptableValueRange<float>(1f, 32f)));
            FireRateMultiplier = Config.Bind("General", "Fire Rate Multiplier", 1f,
                new ConfigDescription("Fire Rate Multiplier",
                    new AcceptableValueRange<float>(0.1f, 32f)));
            AimIntervalMultiplier = Config.Bind("General", "Aiming Interval Multiplier", 1f,
                new ConfigDescription("Aiming Interval Multiplier", new AcceptableValueRange<float>(0.1f, 32f)));
            MovementSpeedMultiplier = Config.Bind("General", "Movement Speed Multiplier", 1f,
                new ConfigDescription("Movement Speed Multiplier", new AcceptableValueRange<float>(0.1f, 32f)));

            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");
        }
    }
}
