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

namespace AgainstTheStorm {
    [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<int> ProductionMultiplier;
        public static ConfigEntry<int> DepositChargesMultiplier;
        public static ConfigEntry<float> VillagerSpeedMultiplier;
        public static ConfigEntry<float> ProductionSpeedMultiplier;
        public static ConfigEntry<float> NewcomverRateMultiplier;
        public static ConfigEntry<int> VillagerCapacityMultiplier;
        public static ConfigEntry<float> TraderRateMultiplier;
        public static ConfigEntry<int> TraderMerchMultiplier;
        public static ConfigEntry<float> HearthRangeMultiplier;
        public static ConfigEntry<float> HouseCapacityMultiplier;
        public static ConfigEntry<float> NewcomerBonusMultiplier;
        public static ConfigEntry<int> GameSpeedMultiplier;
        public static ConfigEntry<int> AdditionalNewcomerBonus;
        public static ConfigEntry<float> MetaCurrencyMultiplier;
        public static ConfigEntry<float> TradeRouteSpeedMultiplier;

        // public static ConfigEntry<float> wheelTorqueMultiplier;
        // public static ConfigEntry<float> wheelSpeedMultiplier;
        // public static ConfigEntry<float> jetThrustMultiplier;

        public void Awake() {
            ProductionMultiplier = Config.Bind("General", "ProductionMultiplier", 1,
                new ConfigDescription("ProductionMultiplier", new AcceptableValueRange<int>(1, 512)));
            DepositChargesMultiplier = Config.Bind("General", "DepositChargesMultiplier", 1,
                new ConfigDescription("DepositChargesMultiplier", new AcceptableValueRange<int>(1, 512)));
            VillagerSpeedMultiplier = Config.Bind("General", "VillagerSpeedMultiplier", 1f,
                new ConfigDescription("VillagerSpeedMultiplier", new AcceptableValueRange<float>(1f, 128f)));
            ProductionSpeedMultiplier = Config.Bind("General", "ProductionSpeedMultiplier", 1f,
                new ConfigDescription("ProductionSpeedMultiplier", new AcceptableValueRange<float>(1f, 256f)));
            NewcomverRateMultiplier = Config.Bind("General", "NewcomverRateMultiplier", 1f,
                new ConfigDescription("NewcomverRateMultiplier", new AcceptableValueRange<float>(1f, 128f)));
            VillagerCapacityMultiplier = Config.Bind("General", "VillagerCapacityMultiplier", 1,
                new ConfigDescription("VillagerCapacityMultiplier", new AcceptableValueRange<int>(1, 32)));
            TraderRateMultiplier = Config.Bind("General", "TraderRateMultiplier", 1f,
                new ConfigDescription("TraderRateMultiplier", new AcceptableValueRange<float>(1f, 128f)));
            TraderMerchMultiplier = Config.Bind("General", "TraderMerchMultiplier", 1,
                new ConfigDescription("TraderMerchMultiplier", new AcceptableValueRange<int>(1, 128)));
            HearthRangeMultiplier = Config.Bind("General", "HearthRangeMultiplier", 1f,
                new ConfigDescription("HearthRangeMultiplier", new AcceptableValueRange<float>(1f, 128f)));
            HouseCapacityMultiplier = Config.Bind("General", "HouseCapacityMultiplier", 1f,
                new ConfigDescription("HouseCapacityMultiplier", new AcceptableValueRange<float>(1f, 32f)));
            NewcomerBonusMultiplier = Config.Bind("General", "NewcomerBonusMultiplier", 1f,
                new ConfigDescription("NewcomerBonusMultiplier", new AcceptableValueRange<float>(1f, 32f)));
            GameSpeedMultiplier = Config.Bind("General", "GameSpeedMultiplier", 1,
                new ConfigDescription("GameSpeedMultiplier", new AcceptableValueRange<int>(1, 32)));
            AdditionalNewcomerBonus = Config.Bind("General", "AdditionalNewcomerBonus", 0,
                new ConfigDescription("AdditionalNewcomerBonus", new AcceptableValueRange<int>(0, 512)));
            MetaCurrencyMultiplier = Config.Bind("General", "MetaCurrencyMultiplier", 1f,
                new ConfigDescription("MetaCurrencyMultiplier", new AcceptableValueRange<float>(1f, 512f)));
            TradeRouteSpeedMultiplier = Config.Bind("General", "TradeRouteSpeedMultiplier", 1f,
                new ConfigDescription("TradeRouteSpeedMultiplier", new AcceptableValueRange<float>(1f, 512f)));
            // minerMiningSpeed = Config.Bind("Production", "Miner Mining Speed", 1f,
            //     new ConfigDescription("Miner Mining Speed", new AcceptableValueRange<float>(1f, 32f)));
            //
            // allProjectilesHoming = Config.Bind("General", "Make All Projectiles Home", false);

            // shootingSpeedMultiplier.SettingChanged += (sender, args) => WeaponPropertiesManager.DoPatch();
            // energyGenMultiplier.SettingChanged += (sender, args) => GeneratorPropertiesManager.DoPatch();
            // magnetStrenghtMultiplier.SettingChanged += (sender, args) => MagnetPropertiesManager.DoPatch();
            // magnetRadiusMultiplier.SettingChanged += (sender, args) => MagnetPropertiesManager.DoPatch();
            // beamStrenghtMultiplier.SettingChanged += (sender, args) => BeamPropertiesManager.DoPatch();
            // beamRadiusMultiplier.SettingChanged += (sender, args) => BeamPropertiesManager.DoPatch();
            // fuelTankRefillMultiplier.SettingChanged += (sender, args) => FuelPropertiesManager.DoPatch();
            // fuelTankCapacityMultiplier.SettingChanged += (sender, args) => FuelPropertiesManager.DoPatch();
            // wheelTorqueMultiplier.SettingChanged += (sender, args) => WheelPropertiesManager.DoPatch();
            // wheelSpeedMultiplier.SettingChanged += (sender, args) => WheelPropertiesManager.DoPatch();
            // jetThrustMultiplier.SettingChanged += (sender, args) => ThrusterPropertiesManager.DoPatch();
            // minerGroundArea.SettingChanged += (sender, args) => MinerPropertiesManager.DoPatch();
            // minerMiningSpeed.SettingChanged += (sender, args) => MinerPropertiesManager.DoPatch();

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