using PlantBox.Shared.Communication.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PlantBox.Shared.Communication
{
///
/// Represent a Packet as described in the Wiki > Protocol
///
public class CommandPacket
{
///
/// A valid packet command, see the Wiki > Commands
///
public Command Command { get; }
///
/// A valid id
///
public ulong ID { get; }
///
/// Any arguments, see the Wiki page of a command for more infos
///
public string[] Arguments { get; }
///
/// Create a
///
///
///
///
public CommandPacket(Command command, ulong id, string[] arguments)
{
Command = command;
ID = id;
Arguments = arguments ?? Array.Empty();
}
///
/// Create a
///
///
///
public CommandPacket(Command command, params string[] arguments)
{
Command = command;
ID = ulong.Parse(arguments[0]);
Arguments = arguments != null && arguments.Length > 1 ? arguments.Skip(1).ToArray() : Array.Empty();
}
///
/// Convert a to a valid text representation of a packet, see Wiki > Protocol
///
/// A valid packet text representation, ready to be sent
public override string ToString()
{
return $"{Command.ToString().ToUpperInvariant()}\n{ID}{(Arguments.Length > 0 ? $";{string.Join(";", Arguments)}" : string.Empty)}\n";
}
}
}