using System;
using System.Collections.Generic;
using LitJson;

namespace Wizard;

public class GatheringInfo
{
	public enum eState
	{
		BEFORE_BATTLE = 1,
		ACTIVE_BATTLE,
		AFTER_BATTLE
	}

	public GatheringRule Rule { get; private set; }

	public eState State { get; private set; }

	public GatheringRule.eRole Role { get; private set; }

	public string Id { get; private set; }

	public int CurrentMemberCount { get; private set; }

	public List<GatheringUserInfo> MemberList { get; private set; }

	public GatheringUserInfo OwnerInfo { get; private set; }

	public string BattleStartTime { get; private set; }

	public string BattleStartTimeShort { get; private set; }

	public string FinishTime { get; private set; }

	public bool IsGatheringFinish { get; private set; }

	public string Description { get; private set; }

	public bool CanBattleJoin
	{
		get
		{
			if (Role == GatheringRule.eRole.OWNER && !Rule.IsOwnerEntryBattle)
			{
				return false;
			}
			return true;
		}
	}

	public GatheringInfo()
	{
	}

	public GatheringInfo(JsonData data)
	{
		JsonData jsonData = data["gathering"];
		Rule = new GatheringRule(jsonData, data["gathering_config"]);
		CurrentMemberCount = jsonData["join_member_count"].ToInt();
		Id = jsonData["id"].ToString();
		int num = jsonData["master_viewer_id"].ToInt();
		Role = ((num == PlayerStaticData.UserViewerID) ? GatheringRule.eRole.OWNER : GatheringRule.eRole.GUEST);
		MemberList = new List<GatheringUserInfo>();
		if (data.Keys.Contains("members"))
		{
			JsonData jsonData2 = data["members"];
			for (int i = 0; i < jsonData2.Count; i++)
			{
				GatheringUserInfo gatheringUserInfo = new GatheringUserInfo(jsonData2[i]);
				gatheringUserInfo.IsOwner = gatheringUserInfo.ViewerId == num;
				MemberList.Add(gatheringUserInfo);
			}
		}
		OwnerInfo = new GatheringUserInfo(jsonData["master_user"]);
		DateTime dateTime = DateTime.Parse(jsonData["battle_begin_time"].ToString());
		BattleStartTime = ConvertTime.ToLocal(dateTime).ToString();
		BattleStartTimeShort = ConvertTime.ToLocal(dateTime, ConvertTime.FORMAT.TIME_DATE_SHORT).ToString();
		if (jsonData.TryGetValue("battle_end_time", out var value))
		{
			FinishTime = ConvertTime.ToLocal(DateTime.Parse(value.ToString())).ToString();
		}
		if (jsonData.TryGetValue("is_battle_finished", out var value2))
		{
			IsGatheringFinish = value2.ToInt() != 0;
		}
		Description = jsonData["description"].ToString();
		State = (eState)jsonData["status"].ToInt();
	}
}
