using System;
using Cute;
using HarmonyLib;

namespace SVSimLoader.Patches;

[HarmonyPatch]
public static class UrlPatches
{
    [HarmonyPatch(typeof(CustomPreference), nameof(CustomPreference.GetApplicationServerURL))]
    [HarmonyPrefix]
    public static bool GetApplicationServerURL(ref string __result)
    {
        __result = SvSimConfig.ApplicationUrl;
        return false;
    }

    /// <summary>
    /// Redirects the deck-builder server (shadowverse-portal.com in prod) to our app server so
    /// the deck-code mint/resolve pair lands on the emulator's <c>DeckBuilderController</c>.
    /// Both client tasks (<c>GenerateDeckCodeTask</c>, <c>GetDeckDataFromCodeTask</c>) build
    /// their URL as <c>GetDeckBuilderServerURL() + ApiList[type]</c> where the right-hand side
    /// is the bare <c>deck_code?format=msgpack</c> / <c>deck?format=msgpack</c> path — matches
    /// our controller routes once this prefix returns the local server's base URL.
    /// </summary>
    [HarmonyPatch(typeof(CustomPreference), nameof(CustomPreference.GetDeckBuilderServerURL))]
    [HarmonyPrefix]
    public static bool GetDeckBuilderServerURL(ref string __result)
    {
        __result = SvSimConfig.ApplicationUrl;
        return false;
    }
}