using System.Reflection;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using SVSimLoader.Patches;

namespace SVSimLoader
{
    [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
    public class Plugin : BaseUnityPlugin
    {
        internal static ManualLogSource Log;
        private ConfigEntry<string> _applicationUrl;
        private ConfigEntry<bool> _disableEncryption;
        private void Awake()
        {
            Log = base.Logger;
            // Plugin startup logic
            Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
            _applicationUrl = Config.Bind("Urls", "ApplicationUrl", "https://utoongaize.shadowverse.jp/shadowverse/",
                "The URL to the application server.");
            _disableEncryption = Config.Bind("Settings", "DisableEncryption", false,
                "Whether to disable encrypting HTTP requests");
            SvSimConfig.DumpCardDB =
                Config.Bind("Settings", "DumpCardDB", false, "Dumps the loaded cards to a desktop log file").Value;
            Logger.LogInfo($"Connecting to application server at {_applicationUrl.Value}");
            SvSimConfig.ApplicationUrl = _applicationUrl.Value;
            SvSimConfig.DisableEncryption = _disableEncryption.Value;
            var harmony = new Harmony(PluginInfo.PLUGIN_GUID);
            harmony.PatchAll(Assembly.GetExecutingAssembly());
            Logger.LogInfo("Patched");
        }
    }
}