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

namespace Wizard;

public class GatheringUtility : MonoBehaviour
{
	public class RuleTypeInfo
	{
		public string Name { get; private set; }

		public GatheringRule.eType Type { get; private set; }

		public GatheringRule.eTournamentType TournamentType { get; private set; }

		public int MaxMember { get; private set; }

		public bool IsReset { get; private set; }

		public RuleTypeInfo(GatheringRule.eType _eType, GatheringRule.eTournamentType _eTournamentType = GatheringRule.eTournamentType.NONE, bool _isReset = false)
		{
			Type = _eType;
			TournamentType = _eTournamentType;
			Name = GetGatheringTypeString(Type, TournamentType, _isReset);
			MaxMember = GetMaxMemberNumber(Type);
			IsReset = _isReset;
		}
	}

	public static List<RuleTypeInfo> GetAllGatheringRule()
	{
		List<RuleTypeInfo> list = new List<RuleTypeInfo>();
		foreach (GatheringRule.eType value in Enum.GetValues(typeof(GatheringRule.eType)))
		{
			if (value == GatheringRule.eType.TOURNAMENT)
			{
				foreach (GatheringRule.eTournamentType value2 in Enum.GetValues(typeof(GatheringRule.eTournamentType)))
				{
					switch (value2)
					{
					case GatheringRule.eTournamentType.DOUBLE_ELIMINATION:
						list.Add(new RuleTypeInfo(value, value2, _isReset: true));
						list.Add(new RuleTypeInfo(value, value2));
						break;
					default:
						list.Add(new RuleTypeInfo(value, value2));
						break;
					case GatheringRule.eTournamentType.NONE:
						break;
					}
				}
			}
			else
			{
				list.Add(new RuleTypeInfo(value));
			}
		}
		return list;
	}

	public static string GetGatheringTypeString(GatheringInfo gatheringInfo)
	{
		return GetGatheringTypeString(gatheringInfo.Rule.Type, gatheringInfo.Rule.TournamentType, gatheringInfo.Rule.IsReset);
	}

	public static string GetGatheringTypeString(GatheringRule.eType _eType, GatheringRule.eTournamentType _eTournamentType = GatheringRule.eTournamentType.NONE, bool isReset = false)
	{
		SystemText systemText = Data.SystemText;
		switch (_eType)
		{
		case GatheringRule.eType.FREE_BATTLE:
			return systemText.Get("Gathering_0033");
		case GatheringRule.eType.TOURNAMENT:
			switch (_eTournamentType)
			{
			case GatheringRule.eTournamentType.SINGLE_ELIMINATION:
				return systemText.Get("Gathering_0030");
			case GatheringRule.eTournamentType.DOUBLE_ELIMINATION:
				if (!isReset)
				{
					return systemText.Get("Gathering_0035");
				}
				return systemText.Get("Gathering_0031");
			default:
				Debug.LogError("未知のトーナメントタイプが追加されています:" + _eTournamentType);
				return "";
			}
		default:
			Debug.LogError("未知のタイプが追加されています:" + _eType);
			return "";
		}
	}

	public static int GetMaxMemberNumber(GatheringRule.eType _eType)
	{
		if (_eType == GatheringRule.eType.TOURNAMENT)
		{
			return 64;
		}
		return 128;
	}

	public static IEnumerator JoinRoom(RoomConnectController.InitializeParameter param, string battleId)
	{
		UIManager.GetInstance().createInSceneCenterLoading(notBlack: true);
		GameMgr.GetIns().GetDataMgr().m_BattleType = DataMgr.BattleType.RoomBattle;
		RoomConnectController room = new RoomConnectController(param);
		yield return UIManager.GetInstance().StartCoroutine(room.StartConnect(battleId));
		if (room.ConnectRoomResultType == RoomConnectController.ConnectRoomResult.SUCCESS)
		{
			UIManager.GetInstance()._Footer.InviteIconDisp(inDisp: false);
			UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.Room);
		}
		UIManager.GetInstance().closeInSceneCenterLoading();
	}
}
