using System.IO;

namespace Crysome.Common.Network.Packets.Client;

public class ReadFileResponsePacket : IPacket
{
	public bool Success { get; set; }

	public string ErrorMessage { get; set; }

	public byte[] Data { get; set; }

	public long TransferId { get; set; }

	public ReadFileResponsePacket()
	{
	}

	public ReadFileResponsePacket(bool success, string errorMessage = null, byte[] data = null, long transferId = 0L)
	{
		Success = success;
		ErrorMessage = errorMessage ?? "";
		Data = data;
		TransferId = transferId;
	}

	public void Write(BinaryWriter w)
	{
		w.Write(Success);
		w.Write(ErrorMessage ?? "");
		int num = ((Data != null) ? Data.Length : 0);
		w.Write(num);
		if (Data != null && num > 0)
		{
			w.Write(Data);
		}
		w.Write(TransferId);
	}

	public void Read(BinaryReader r)
	{
		Success = r.ReadBoolean();
		ErrorMessage = r.ReadString();
		int num = r.ReadInt32();
		Data = ((num > 0) ? r.ReadBytes(num) : null);
		TransferId = ((r.BaseStream.Position < r.BaseStream.Length) ? r.ReadInt64() : 0);
	}
}
