using System;
using System.IO;

namespace Crysome.Common.Network.Packets.Client;

public class AudioDevicesResponsePacket : IPacket
{
	public string[] DeviceNames { get; set; } = Array.Empty<string>();

	public AudioDevicesResponsePacket()
	{
	}

	public AudioDevicesResponsePacket(string[] names)
	{
		DeviceNames = names ?? Array.Empty<string>();
	}

	public void Write(BinaryWriter w)
	{
		string[] deviceNames = DeviceNames;
		w.Write((deviceNames != null) ? deviceNames.Length : 0);
		if (DeviceNames != null)
		{
			string[] deviceNames2 = DeviceNames;
			foreach (string text in deviceNames2)
			{
				w.Write(text ?? "");
			}
		}
	}

	public void Read(BinaryReader r)
	{
		int num = r.ReadInt32();
		DeviceNames = new string[num];
		for (int i = 0; i < num; i++)
		{
			DeviceNames[i] = r.ReadString();
		}
	}
}
