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

namespace PlcSiemens.ProtocolHandle
{
    public class SetPasswordHandle : IPacketHandle
    {
        public SetPasswordRequest Request { get; set; }
        public HandleResponse<HeaderPacket> Response { get; set; }
        public string Password { get; set; }
        public ResultCode ResultCode { get; set; }

        public SetPasswordHandle()
        {
            ResultCode = ResultCode.Unknown;
            Request = new SetPasswordRequest();
        }

        public void Handle(IIsoSender sender)
        {
            Request.Password = Password;
            Response = sender.IsoSend<SetPasswordRequest, HandleResponse<HeaderPacket>>(Request);
            if (Response == null) return;

            ResultCode = Response.Params.Err;
        }
    }
}
