using System;
using System.Collections.Generic;
using System.Linq;
using MarketData.MarketDataModel;
using Microsoft.Research.DynamicDataDisplay.DataSources;

namespace TradeBlotter.Model
{
  public delegate double ValueConverter(double value);
  public class TimeSeriesModel
  {
    public static CompositeDataSource GenerateCompositeDataSource(TimeSeriesCollection timeSeriesCollection)
    {
      if (null == timeSeriesCollection || 0 == timeSeriesCollection.Count) return null;
      CompositeDataSource compositeDataSource;
      var xData = new EnumerableDataSource<DateTime>(timeSeriesCollection.Select(x => x.AsOf.Date));
      xData.SetXMapping(x => (x.Ticks / 10000000000.0));
      var yData = new EnumerableDataSource<double>(timeSeriesCollection.Select(y => y.Value));
      yData.SetYMapping(y => y);
      compositeDataSource = xData.Join(yData);
      return compositeDataSource;
    }
    public static CompositeDataSource GenerateCompositeDataSource(TimeSeriesCollection timeSeriesCollection,ValueConverter valueConverter)
    {
      if (null == timeSeriesCollection || 0 == timeSeriesCollection.Count) return null;
      CompositeDataSource compositeDataSource;
      var xData = new EnumerableDataSource<DateTime>(timeSeriesCollection.Select(x => x.AsOf.Date));
      xData.SetXMapping(x => (x.Ticks / 10000000000.0));
      var yData = new EnumerableDataSource<double>(timeSeriesCollection.Select(y => valueConverter(y.Value)));
      yData.SetYMapping(y => y);
      compositeDataSource = xData.Join(yData);
      return compositeDataSource;
    }
  }
}
