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

namespace PlcSiemens.Protocol.DateTime
{
    public class GetDateTimeRequest : IBuildRequest
    {
        public HeaderPacket Header { get; set; }
        public ParamsRequest Params { get; set; }
        public uint Data { get; set; }

        public GetDateTimeRequest()
        {
            Header = new HeaderPacket();
            Params = new ParamsRequest();
        }

        public void Build()
        {
            Header.Build(PduType.Userdata, Params.PacketLength, 4);
            Params.Build(true, 0x00, GrType.GrClock, PduFuncType.SFunReadClock);
            Data = 0x0A000000;
        }

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