using System.Collections.Generic;
using System.Reflection;
using MaidStatus;
using Mono.Cecil;
using NeighPatcher;
using PrivateMaidMode;

namespace AllMaidsInPrivateMode.Patcher
{
    public static class Patcher
    {
        public static readonly string[] TargetAssemblyNames = { "Assembly-CSharp.dll" };

        public static void Patch(AssemblyDefinition ad)
        {
            NeighPatcher.NeighPatcher.PatchAll(ad, "AllMaidsInPrivateMode.Patcher.Hooks");
        }
    }

    public static class Hooks
    {
        [NeighPatch("Assembly-CSharp", "PrivateMaidMode.PrivateCharaSelectMain", "OnCall")]
        public static void OnCreate()
        {
            var field = typeof(PrivateCharaSelectMain).GetField("<>f__mg$cache0",
                                                                BindingFlags.Static | BindingFlags.NonPublic);

            field.SetValue(
                null, new uGUICharacterSelectManager.CallBackMaidList(uGUICharacterSelectManager.DefaultMaidList));
        }

        [NeighPatch("Assembly-CSharp", "PrivateMaidMode.PrivateModeMgr", "CreateListData")]
        public static void OnCreateListData(ref List<Maid> ___maidList)
        {
            var characterMgr = GameMain.Instance.CharacterMgr;
            for (var i = 0; i < characterMgr.GetStockMaidCount(); i++)
            {
                var stockMaid = characterMgr.GetStockMaid(i);
                var status = stockMaid.status;
                if (status.specialRelation != SpecialRelation.Married)
                    ___maidList.Add(stockMaid);
            }
        }
    }
}