using PlcSiemens.O;
using PlcSiemens.Protocol.Common;
using PlcSiemens.Protocol.ListBlocks;

namespace PlcSiemens.ProtocolHandle
{
    public class ListBlocksHandle : IPacketHandle
    {
        public ListBlocksRequest Request { get; set; }
        public ListBlocksResponse Response { get; set; }

        public ResultCode ResultCode
        {
            get;
            set;
        }

        public ListBlocksHandle()
        {
            ResultCode = ResultCode.Unknown;
            Request = new ListBlocksRequest();
        }

        public void Handle(IIsoSender sender)
        {
            Response = sender.IsoSend<ListBlocksRequest, ListBlocksResponse>(Request);
            if (Response == null) return;

            ResultCode = Response.Data.Ret;
            if (Response.Params.Err != ResultCode.OK) return;
            if (Response.Data.Ret == ResultCode.OKFF)
                ResultCode = ResultCode.OK;
        }
    }
}
