/*
 * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
 * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

using System;
using System.Collections.Generic;

namespace QuantConnect.Data.UniverseSelection
{
    /// <summary>
    /// Provides a functional implementation of <see cref="Universe"/>
    /// </summary>
    public class FuncUniverse : Universe
    {
        private readonly SubscriptionSettings _subscriptionSettings;
        private readonly Func<IEnumerable<BaseData>, IEnumerable<Symbol>> _universeSelector;

        /// <summary>
        /// Gets the settings used for subscriptons added for this universe
        /// </summary>
        public override SubscriptionSettings SubscriptionSettings
        {
            get { return _subscriptionSettings; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FuncUniverse"/> class
        /// </summary>
        /// <param name="configuration">The configuration used to resolve the data for universe selection</param>
        /// <param name="subscriptionSettings">The settings used for new subscriptions generated by this universe</param>
        /// <param name="universeSelector">Returns the symbols that should be included in the universe</param>
        public FuncUniverse(SubscriptionDataConfig configuration, SubscriptionSettings subscriptionSettings, Func<IEnumerable<BaseData>, IEnumerable<Symbol>> universeSelector)
            : base(configuration)
        {
            _universeSelector = universeSelector;
            _subscriptionSettings = subscriptionSettings;
        }

        /// <summary>
        /// Performs an initial, coarse filter
        /// </summary>
        /// <param name="data">The coarse fundamental data</param>
        /// <returns>The data that passes the filter</returns>
        public override IEnumerable<Symbol> SelectSymbols(IEnumerable<BaseData> data)
        {
            return _universeSelector(data);
        }
    }
}