using System.Collections.Generic;

namespace Wizard;

public class GatheringTornamentCreateTask : BaseTask
{
	public class DeckEntry
	{
		public int deck_no;

		public string deck_name;

		public DeckEntry(DeckData deck)
		{
			deck_no = deck.GetDeckID();
			deck_name = deck.GetDeckName();
		}
	}

	public class TornamentGatheringCreateTaskParam : BaseParam
	{
		public int gathering_type;

		public int is_reset;

		public int join_member_limit;

		public int is_master_joined;

		public int deck_format;

		public int battle_type;

		public int watch_type;

		public long battle_begin_timestamp;

		public Dictionary<string, DeckEntry> deck_list = new Dictionary<string, DeckEntry>();

		public int tournament_format;
	}

	public GatheringTornamentCreateTask()
	{
		base.type = ApiType.Type.GatheringCreate;
	}

	public void SetParameter(GatheringRule rule, List<DeckData> deckList)
	{
		TornamentGatheringCreateTaskParam tornamentGatheringCreateTaskParam = new TornamentGatheringCreateTaskParam();
		tornamentGatheringCreateTaskParam.gathering_type = (int)rule.Type;
		tornamentGatheringCreateTaskParam.join_member_limit = rule.MaxMember;
		tornamentGatheringCreateTaskParam.is_master_joined = (rule.IsOwnerEntryBattle ? 1 : 0);
		tornamentGatheringCreateTaskParam.deck_format = Data.FormatConvertApi(rule.BattleParameterInstance.DeckFormat);
		tornamentGatheringCreateTaskParam.battle_type = (int)rule.BattleParameterInstance.Rule;
		tornamentGatheringCreateTaskParam.watch_type = (int)rule.WatchSetting;
		tornamentGatheringCreateTaskParam.battle_begin_timestamp = (long)ConvertTime.DateTimeToUnixTime(rule.BattleStartUtcTime);
		if (deckList != null)
		{
			for (int i = 0; i < deckList.Count; i++)
			{
				tornamentGatheringCreateTaskParam.deck_list[i.ToString()] = new DeckEntry(deckList[i]);
			}
		}
		tornamentGatheringCreateTaskParam.tournament_format = (int)rule.TournamentType;
		if (rule.TournamentType == GatheringRule.eTournamentType.DOUBLE_ELIMINATION)
		{
			tornamentGatheringCreateTaskParam.is_reset = (rule.IsReset ? 1 : 0);
		}
		else
		{
			tornamentGatheringCreateTaskParam.is_reset = 0;
		}
		base.Params = tornamentGatheringCreateTaskParam;
	}
}
