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

namespace Wizard;

public class ChatInfo
{
	public GatheringMatchedRoom GatheringMatchedRoom;

	public List<ChatMessageInfo> MessageList { get; private set; }

	public List<ChatMessageInfo> VisibleMessageList { get; private set; }

	public bool IsIncludeInvisibleMessage { get; private set; }

	public int WaitInterval { get; private set; }

	public ChatInfo(JsonData json)
	{
		initialize();
		ParseJsonData(json);
	}

	private void initialize()
	{
		MessageList = new List<ChatMessageInfo>();
		WaitInterval = 0;
		GatheringMatchedRoom = null;
	}

	private void ParseJsonData(JsonData json)
	{
		List<ChatUserInfo> list = new List<ChatUserInfo>();
		JsonData jsonData = json["users"];
		for (int i = 0; i < jsonData.Count; i++)
		{
			list.Add(new ChatUserInfo(jsonData[i]));
		}
		JsonData jsonData2 = json["chat_message"];
		for (int j = 0; j < jsonData2.Count; j++)
		{
			ChatMessageInfo chatMessageInfo = new ChatMessageInfo(jsonData2[j], list);
			if (chatMessageInfo.UserInfo != null && (chatMessageInfo.MessageType != ChatMessageInfo.eMessageType.ROOM_MATCH || chatMessageInfo.RoomData == null || chatMessageInfo.UserInfo.ViewerId != PlayerStaticData.UserViewerID))
			{
				MessageList.Add(new ChatMessageInfo(jsonData2[j], list));
			}
		}
		VisibleMessageList = MessageList.Where((ChatMessageInfo message) => message.IsVisibleMessage).ToList();
		IsIncludeInvisibleMessage = MessageList.Any((ChatMessageInfo message) => !message.IsVisibleMessage);
		WaitInterval = json["wait_interval"].ToInt();
		if (json.Keys.Contains("matched_room_id"))
		{
			GatheringMatchedRoom = new GatheringMatchedRoom(json["matched_room_id"].ToString());
		}
	}
}
