using PlcSiemens.O;
using PlcSiemens.Protocol.Header;

namespace PlcSiemens.Protocol.WriteData
{
    /// <summary>
    ///
    /// </summary>
    public class WriteResponse : IBuildResponse
    {
        /// <summary>
        ///
        /// </summary>
        public HeaderPacketWithErrorCode Header { get; set; }

        /// <summary>
        ///
        /// </summary>
        public WriteParamsResponse Params { get; set; }

        /// <summary>
        ///
        /// </summary>
        public WriteItemResponse[] Data { get; set; }

        /// <summary>
        ///
        /// </summary>
        public WriteResponse()
        {
            Header = new HeaderPacketWithErrorCode();
            Params = new WriteParamsResponse();
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="buffer"></param>
        public void Build(ByteBuffer buffer)
        {
            Header.Build(buffer);
            Params.Build(buffer);

            Data = new WriteItemResponse[Params.ItemCount];
            for (int i = 0; i < Params.ItemCount; i++)
            {
                Data[i] = new WriteItemResponse();
                Data[i].Build(buffer);
            }
        }
    }
}
