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

namespace PlcSiemens.Protocol.Szl
{
    public class SzlRequest : IBuildRequest
    {
        public HeaderPacket Header { get; set; }
        public ParamsRequest Params { get; set; }
        public SzlDataRequest Data { get; set; }

        public bool First = true;
        public byte Seq = 0x00;
        public ushort ID { get; set; }
        public ushort Index = 0x0000;

        public SzlRequest()
        {
            Header = new HeaderPacket();
            Params = new ParamsRequest();
            Data = new SzlDataRequest();
        }

        public void Build()
        {
            Params.Build(First, Seq, GrType.GrSzl, PduFuncType.SFunReadSzl);
            Data.Build(First, ID, Index);
            Header.Build(PduType.Userdata, Params.PacketLength, Data.PacketLength);
        }

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

            return buffer;
        }
    }
}
