using InABox.Clients;
using InABox.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InABox.WebSocket.Shared
{
    public class PushRequest : Request, ISerializeBinary
    {
        public override RequestMethod GetMethod() => RequestMethod.Push;
    }

    public class PushResponse : Response, ISerializeBinary
    {
        public int? SocketPort { get; set; }

        public override void SerializeBinary(CoreBinaryWriter writer)
        {
            base.SerializeBinary(writer);

            if(SocketPort != null)
            {
                writer.Write(true);
                writer.Write(SocketPort.Value);
            }
            else
            {
                writer.Write(false);
            }
        }

        public override void DeserializeBinary(CoreBinaryReader reader)
        {
            base.DeserializeBinary(reader);

            if(reader.ReadBoolean())
            {
                SocketPort = reader.ReadInt32();
            }
            else
            {
                SocketPort = null;
            }
        }
    }
}
