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

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

        public byte UploadID { get; set; }
        public PduType PduType = PduType.PduUpload;

        public UploadRequest()
        {
            Header = new HeaderPacket();
            Params = new UploadParamsRequest();
        }

        public void Build()
        {
            Params.Build(UploadID, PduType);
            Header.Build(PduType.Request, Params.PacketLength, 0x00);
        }

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