using System.IO;

namespace Crysome.Common.Network.Packets.Server;

public class RequestAudioPacket : IPacket
{
	public int Seconds { get; set; } = 5;

	public int DeviceIndex { get; set; }

	public RequestAudioPacket()
	{
	}

	public RequestAudioPacket(int seconds, int deviceIndex = 0)
	{
		Seconds = seconds;
		DeviceIndex = deviceIndex;
	}

	public void Write(BinaryWriter w)
	{
		w.Write(Seconds);
		w.Write(DeviceIndex);
	}

	public void Read(BinaryReader r)
	{
		Seconds = r.ReadInt32();
		try
		{
			if (r.BaseStream.Position < r.BaseStream.Length)
			{
				DeviceIndex = r.ReadInt32();
			}
		}
		catch
		{
			DeviceIndex = 0;
		}
	}
}
