﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Reflection;
using System.Security.Policy;
using HarmonyLib;

namespace undead_universal_patch.Patches
{
    [HarmonyPatch]
    class UWR_Str_Str_Patch
    {
        const string TargetTypeName = "UnityEngine.Networking.UnityWebRequest";
        const string UWRParams = "(Str-Str)";
        static readonly Type targetType = AccessTools.TypeByName(TargetTypeName);

        static bool Prepare() => UWRPatchNoArg.Prepare();

        static MethodBase TargetMethod()
        {
            return AccessTools.Constructor(targetType, [ typeof(string), typeof(string) ]);
        }

        [HarmonyPrefix]
        public static bool Prefix(ref string url)
        {
            // TODO: This is duplicated across all UWR patch files, reduce boilerplate
            // TODO: This is not the most elegant way to patch out amplitude - find a better fix
            if (url.Contains("api.amplitude.com") && GenericConfig.DisableAmplitude.Value) return false;
            else return true;
        }

        [HarmonyPostfix]
        static void Postfix(object __instance) => UWRPatchNoArg.InPostfix(__instance, UWRParams);
    }
}
