using System;
using System.Collections.Generic;
using System.Linq;
using Chernobyl.Collections.Generic.Event;
using Chernobyl.Plugin;

namespace Chernobyl.Mathematics
{
    /// <summary>
    /// Services related to Chernobyl.Mathematics.
    /// </summary>
    public interface IServices : IEventCollection<Object>
    {}

    /// <summary>
    /// Basic implementation of <see cref="IServices"/> used to store services
    /// for Chernobyl.Mathematics.
    /// </summary>
    public class Services : DecoratingEventList<Object>, IServices, IPlugin
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Services"/> class.
        /// </summary>
        public Services(IEventCollection<Object> services)
        {
            services.Add(this);

            Add(new Movement.Services());
        }
    }

    /// <summary>
    /// Extension and utility methods for <see cref="IServices"/>.
    /// </summary>
    public static class Extensions
    {
        /// <summary>
        /// Returns the services list for Chernobyl.Mathematics.
        /// </summary>
        /// <param name="services">The list to look into for the
        /// Chernobyl.Mathematics services list.</param>
        /// <returns>The services list for Chernobyl.Mathematics.</returns>
        public static IEventEnumerable<Object> Mathematics(this IEventEnumerable<Object> services)
        {
            return ((IEnumerable<object>)services).OfType<Services>().First();
        }
    }
}