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

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

        public System.DateTime DateTime { get; set; }

        public SetDateTimeRequest()
        {
            Header = new HeaderPacket();
            Params = new ParamsRequest();
            Data = new DateTimeData();
        }

        public void Build()
        {
            Header.Build(PduType.Userdata, Params.PacketLength, Data.PacketLength);
            Params.Build(true, 0x00, GrType.GrClock, PduFuncType.SFunSetClock);
            Data.Build(DateTime);
        }

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