using PlcSiemens.O;
using PlcSiemens.Protocol.Common;
using PlcSiemens.Protocol.Header;

namespace PlcSiemens.Protocol.Upload
{
    public class StartUploadRequest : IBuildRequest
    {
        public HeaderPacket Header { get; set; }
        public StartUploadParamsRequest Params { get; set; }

        public BlockType BlockType { get; set; }
        public ushort BlockNum { get; set; }

        public StartUploadRequest()
        {
            Header = new HeaderPacket();
            Params = new StartUploadParamsRequest();
        }

        public void Build()
        {
            Params.Build(BlockType, BlockNum);
            Header.Build(PduType.Request, Params.PacketLength, 0x000);
        }

        public ByteBuffer GetBuffer()
        {
            ByteBuffer buffer = ByteBuffer.Allocate();
            Header.GetByteBuffer(buffer);
            Params.GetByteBuffer(buffer);
            return buffer;
        }
    }
}
