using PLC.Siemens.Protocol.ReadData;
using PlcSiemens.O;
using PlcSiemens.Protocol.Header;

namespace PlcSiemens.Protocol.ReadData
{
    public class ReadResponse : IBuildResponse
    {
        public HeaderPacketWithErrorCode Header { get; set; }
        public ReadParamsResponse Params { get; set; }
        public List<ReadItemResponse> DataItems { get; set; }

        public ReadResponse()
        {
            Header = new HeaderPacketWithErrorCode();
            Params = new ReadParamsResponse();
            DataItems = new List<ReadItemResponse>();
        }

        public void Build(ByteBuffer buffer)
        {
            Header.Build(buffer);
            Params.Build(buffer);

            for (int i = 0; i < Params.ItemCount; i++)
            {
                var item = new ReadItemResponse();
                item.Build(buffer);
                DataItems.Add(item);
            }
        }
    }
}
