using System.Collections.Generic;
using Wizard.RoomMatch;

namespace Wizard;

public static class RoomTwoPickApiVariation
{
	public enum VariationType
	{
		DoMatching,
		Finish,
		ResetDeck,
		BeginCreateDeck,
		SelectClass,
		SelectCardSet
	}

	private static readonly Dictionary<VariationType, ApiType.Type> NormalApiTypes = new Dictionary<VariationType, ApiType.Type>
	{
		{
			VariationType.DoMatching,
			ApiType.Type.OpenRoomBattle2PickBattleDoMatching
		},
		{
			VariationType.Finish,
			ApiType.Type.OpenRoom2PickMatchFinish
		},
		{
			VariationType.ResetDeck,
			ApiType.Type.OpenRoom2PickBattleDeckReset
		},
		{
			VariationType.BeginCreateDeck,
			ApiType.Type.OpenRoom2PickBattleBeginCreateDeck
		},
		{
			VariationType.SelectClass,
			ApiType.Type.OpenRoom2PickBattleSelectClass
		},
		{
			VariationType.SelectCardSet,
			ApiType.Type.OpenRoom2PickBattleSelectCard
		}
	};

	private static readonly Dictionary<VariationType, ApiType.Type> MultiApiTypes = new Dictionary<VariationType, ApiType.Type>
	{
		{
			VariationType.DoMatching,
			ApiType.Type.OpenRoomBattle2PickMultiBattleDoMatching
		},
		{
			VariationType.Finish,
			ApiType.Type.OpenRoom2PickMultiBattleMatchFinish
		},
		{
			VariationType.ResetDeck,
			ApiType.Type.OpenRoom2PickMultiBattleDeckReset
		},
		{
			VariationType.BeginCreateDeck,
			ApiType.Type.OpenRoom2PickMultiBattleBeginCreateDeck
		},
		{
			VariationType.SelectClass,
			ApiType.Type.OpenRoom2PickMultiBattleSelectClass
		},
		{
			VariationType.SelectCardSet,
			ApiType.Type.OpenRoom2PickMultiBattleSelectCard
		}
	};

	private static readonly Dictionary<VariationType, ApiType.Type> BackdraftApiTypes = new Dictionary<VariationType, ApiType.Type>
	{
		{
			VariationType.DoMatching,
			ApiType.Type.OpenRoomBattle2PickDraftBattleDoMatching
		},
		{
			VariationType.Finish,
			ApiType.Type.OpenRoom2PickDraftMatchFinish
		},
		{
			VariationType.ResetDeck,
			ApiType.Type.OpenRoom2PickDraftBattleDeckReset
		},
		{
			VariationType.BeginCreateDeck,
			ApiType.Type.OpenRoom2PickDraftBattleBeginCreateDeck
		},
		{
			VariationType.SelectClass,
			ApiType.Type.OpenRoom2PickDraftBattleSelectClass
		},
		{
			VariationType.SelectCardSet,
			ApiType.Type.OpenRoom2PickDraftBattleSelectCard
		}
	};

	private static readonly Dictionary<VariationType, ApiType.Type> CubeApiTypes = new Dictionary<VariationType, ApiType.Type>
	{
		{
			VariationType.DoMatching,
			ApiType.Type.OpenRoom2PickCubeBattleDoMatching
		},
		{
			VariationType.Finish,
			ApiType.Type.OpenRoom2PickCubeBattleFinish
		},
		{
			VariationType.ResetDeck,
			ApiType.Type.OpenRoom2PickCubeBattleResetDeck
		},
		{
			VariationType.BeginCreateDeck,
			ApiType.Type.OpenRoom2PickCubeBattleBeginCreateDeck
		},
		{
			VariationType.SelectClass,
			ApiType.Type.OpenRoom2PickCubeBattleSelectClass
		},
		{
			VariationType.SelectCardSet,
			ApiType.Type.OpenRoom2PickCubeBattleSelectCardSet
		}
	};

	private static readonly Dictionary<VariationType, ApiType.Type> MultiCubeApiTypes = new Dictionary<VariationType, ApiType.Type>
	{
		{
			VariationType.DoMatching,
			ApiType.Type.OpenRoom2PickCubeMultiBattleDoMatching
		},
		{
			VariationType.Finish,
			ApiType.Type.OpenRoom2PickCubeMultiBattleFinish
		},
		{
			VariationType.ResetDeck,
			ApiType.Type.OpenRoom2PickCubeMultiBattleResetDeck
		},
		{
			VariationType.BeginCreateDeck,
			ApiType.Type.OpenRoom2PickCubeMultiBattleBeginCreateDeck
		},
		{
			VariationType.SelectClass,
			ApiType.Type.OpenRoom2PickCubeMultiBattleSelectClass
		},
		{
			VariationType.SelectCardSet,
			ApiType.Type.OpenRoom2PickCubeMultiBattleSelectCardSet
		}
	};

	private static readonly Dictionary<VariationType, ApiType.Type> BackDraftCubeApiTypes = new Dictionary<VariationType, ApiType.Type>
	{
		{
			VariationType.DoMatching,
			ApiType.Type.OpenRoomBattle2PickCubeDraftBattleDoMatching
		},
		{
			VariationType.Finish,
			ApiType.Type.OpenRoom2PickCubeDraftMatchFinish
		},
		{
			VariationType.ResetDeck,
			ApiType.Type.OpenRoom2PickCubeDraftBattleDeckReset
		},
		{
			VariationType.BeginCreateDeck,
			ApiType.Type.OpenRoom2PickCubeDraftBattleBeginCreateDeck
		},
		{
			VariationType.SelectClass,
			ApiType.Type.OpenRoom2PickCubeDraftBattleSelectClass
		},
		{
			VariationType.SelectCardSet,
			ApiType.Type.OpenRoom2PickCubeDraftBattleSelectCard
		}
	};

	private static readonly Dictionary<VariationType, ApiType.Type> ChaosApiTypes = new Dictionary<VariationType, ApiType.Type>
	{
		{
			VariationType.DoMatching,
			ApiType.Type.OpenRoom2PickChaosBattleDoMatching
		},
		{
			VariationType.Finish,
			ApiType.Type.OpenRoom2PickChaosBattleFinish
		},
		{
			VariationType.ResetDeck,
			ApiType.Type.OpenRoom2PickChaosBattleResetDeck
		},
		{
			VariationType.BeginCreateDeck,
			ApiType.Type.OpenRoom2PickChaosBattleBeginCreateDeck
		},
		{
			VariationType.SelectClass,
			ApiType.Type.OpenRoom2PickChaosBattleSelectClass
		},
		{
			VariationType.SelectCardSet,
			ApiType.Type.OpenRoom2PickChaosBattleSelectCardSet
		}
	};

	private static readonly Dictionary<VariationType, ApiType.Type> MultiChaosApiTypes = new Dictionary<VariationType, ApiType.Type>
	{
		{
			VariationType.DoMatching,
			ApiType.Type.OpenRoom2PickChaosMultiBattleDoMatching
		},
		{
			VariationType.Finish,
			ApiType.Type.OpenRoom2PickChaosMultiBattleFinish
		},
		{
			VariationType.ResetDeck,
			ApiType.Type.OpenRoom2PickChaosMultiBattleResetDeck
		},
		{
			VariationType.BeginCreateDeck,
			ApiType.Type.OpenRoom2PickChaosMultiBattleBeginCreateDeck
		},
		{
			VariationType.SelectClass,
			ApiType.Type.OpenRoom2PickChaosMultiBattleSelectClass
		},
		{
			VariationType.SelectCardSet,
			ApiType.Type.OpenRoom2PickChaosMultiBattleSelectCardSet
		}
	};

	private static readonly Dictionary<VariationType, ApiType.Type> BackdraftChaosApiTypes = new Dictionary<VariationType, ApiType.Type>
	{
		{
			VariationType.DoMatching,
			ApiType.Type.OpenRoomBattle2PickChaosDraftBattleDoMatching
		},
		{
			VariationType.Finish,
			ApiType.Type.OpenRoom2PickChaosDraftMatchFinish
		},
		{
			VariationType.ResetDeck,
			ApiType.Type.OpenRoom2PickChaosDraftBattleDeckReset
		},
		{
			VariationType.BeginCreateDeck,
			ApiType.Type.OpenRoom2PickChaosDraftBattleBeginCreateDeck
		},
		{
			VariationType.SelectClass,
			ApiType.Type.OpenRoom2PickChaosDraftBattleSelectClass
		},
		{
			VariationType.SelectCardSet,
			ApiType.Type.OpenRoom2PickChaosDraftBattleSelectCard
		}
	};

	public static ApiType.Type GetApiType(TwoPickFormat twoPickFormat, RoomConnectController.BattleRule rule, VariationType type)
	{
		Dictionary<VariationType, ApiType.Type> dictionary = NormalApiTypes;
		switch (twoPickFormat)
		{
		case TwoPickFormat.Backdraft:
			dictionary = BackdraftApiTypes;
			break;
		case TwoPickFormat.BackdraftCube:
			dictionary = BackDraftCubeApiTypes;
			break;
		case TwoPickFormat.BackdraftChaos:
			dictionary = BackdraftChaosApiTypes;
			break;
		case TwoPickFormat.Cube:
			dictionary = ((rule != RoomConnectController.BattleRule.Bo3 && rule != RoomConnectController.BattleRule.Bo5) ? CubeApiTypes : MultiCubeApiTypes);
			break;
		case TwoPickFormat.Chaos:
			dictionary = ((rule != RoomConnectController.BattleRule.Bo3 && rule != RoomConnectController.BattleRule.Bo5) ? ChaosApiTypes : MultiChaosApiTypes);
			break;
		default:
			if (rule == RoomConnectController.BattleRule.Bo3 || rule == RoomConnectController.BattleRule.Bo5)
			{
				dictionary = MultiApiTypes;
			}
			break;
		}
		return dictionary[type];
	}
}
