// Copyright (c) The LEGO Group. All rights reserved.

namespace LEGO.AsyncAPI.Models.Any
{
    using System.Collections.Generic;
    using LEGO.AsyncAPI.Models.Interfaces;
    using LEGO.AsyncAPI.Writers;

    /// <summary>
    /// AsyncApi array.
    /// </summary>
    public class AsyncApiArray : List<IAsyncApiAny>, IAsyncApiAny
    {
        /// <summary>
        /// The type of <see cref="IAsyncApiAny"/>.
        /// </summary>
        public AnyType AnyType { get; } = AnyType.Array;

        /// <summary>
        /// Write out contents of AsyncApiArray to passed writer.
        /// </summary>
        /// <param name="writer">Instance of JSON or YAML writer.</param>
        public void Write(IAsyncApiWriter writer)
        {
            writer.WriteStartArray();

            foreach (var item in this)
            {
                writer.WriteAny(item);
            }

            writer.WriteEndArray();
        }
    }
}
