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

namespace PlcSiemens.ProtocolHandle
{
    public class SetDateTimeHandle : IPacketHandle
    {
        public SetDateTimeRequest Request { get; set; }
        public HandleResponse<HeaderPacket> Response { get; set; }
        public DateTime DateTime { get; set; }

        public ResultCode ResultCode { get; set; }

        public void Handle(IIsoSender sender)
        {
            Request.DateTime = DateTime;

            Response = sender.IsoSend<SetDateTimeRequest, HandleResponse<HeaderPacket>>(Request);

            if (Response == null) return;

            //if( Response.Params.Err == ResultCode.OK)
            ResultCode = Response.Params.Err;
        }

        public SetDateTimeHandle()
        {
            ResultCode = ResultCode.Unknown;
            Request = new SetDateTimeRequest();
            DateTime = DateTime.Now;
        }
    }
}
