using System;
using System.IO;

namespace Crysome.Common.Network.Packets.Client;

public class ScreensResponsePacket : IPacket
{
	public ScreenInfo[] Screens { get; set; } = Array.Empty<ScreenInfo>();

	public ScreensResponsePacket()
	{
	}

	public ScreensResponsePacket(ScreenInfo[] screens)
	{
		Screens = screens ?? Array.Empty<ScreenInfo>();
	}

	public void Write(BinaryWriter w)
	{
		ScreenInfo[] screens = Screens;
		w.Write((screens != null) ? screens.Length : 0);
		if (Screens != null)
		{
			ScreenInfo[] screens2 = Screens;
			foreach (ScreenInfo screenInfo in screens2)
			{
				w.Write(screenInfo.Name ?? "");
				w.Write(screenInfo.X);
				w.Write(screenInfo.Y);
				w.Write(screenInfo.Width);
				w.Write(screenInfo.Height);
				w.Write(screenInfo.IsPrimary);
			}
		}
	}

	public void Read(BinaryReader r)
	{
		int num = r.ReadInt32();
		Screens = new ScreenInfo[num];
		for (int i = 0; i < num; i++)
		{
			Screens[i] = new ScreenInfo
			{
				Name = r.ReadString(),
				X = r.ReadInt32(),
				Y = r.ReadInt32(),
				Width = r.ReadInt32(),
				Height = r.ReadInt32(),
				IsPrimary = r.ReadBoolean()
			};
		}
	}
}
