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

namespace PlcSiemens.ProtocolHandle
{
    public class DataBlockInfoHandle : IPacketHandle
    {
        public DataBlockInfoRequest Request { get; set; }
        public DataBlockInfoResponse Response { get; set; }
        public BlockType BlockType { get; set; }
        public ushort DB { get; set; }

        public ResultCode ResultCode { get; set; }

        public DataBlockInfoHandle()
        {
            ResultCode = ResultCode.Unknown;
            Request = new DataBlockInfoRequest();
        }

        public void Handle(IIsoSender sender)
        {
            Request.BlockType = BlockType;
            Request.DB = DB;
            Response = sender.IsoSend<DataBlockInfoRequest, DataBlockInfoResponse>(Request);

            if (Response == null) return;

            ResultCode = Response.Params.Err;
        }
    }
}
