﻿namespace JDKing.JsonLite.Ast
{
    using System.Collections.Generic;
    using System.Xml;
    using System.Xml.Serialization;

    [XmlRoot("root")]
    public class JsonArray : JsonValue
    {
        public const string XmlElementName = "array";

        public JsonArray()
        {
            Values = new List<JsonValue>();
        }

        public List<JsonValue> Values { get; set; }

        public override void WriteXml(XmlWriter writer)
        {
            writer.WriteStartElement(XmlElementName);
            foreach (var item in Values)
            {
                if (!(item is JsonObject))
                {
                    writer.WriteStartElement("value");
                }

                item.WriteXml(writer);

                if (!(item is JsonObject))
                {
                    writer.WriteEndElement();
                }
            }

            writer.WriteEndElement();
        }
    }
}