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

namespace TradeBlotter.Model
{
  public class ResistanceAndSupportModel
  {
    private ResistanceAndSupportModel()
    {
    }
    public static CompositeDataSource R1(List<ResistanceSupport> resistanceSupportList)
    {
      if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
      CompositeDataSource compositeDataSource;
      var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
      xData.SetXMapping(x => (x.Ticks / 10000000000.0));
      var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.Resistance1));
      yData.SetYMapping(y => y);
      compositeDataSource = xData.Join(yData);
      return compositeDataSource;
    }
    public static CompositeDataSource S1(List<ResistanceSupport> resistanceSupportList)
    {
      if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
      CompositeDataSource compositeDataSource;
      var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
      xData.SetXMapping(x => (x.Ticks / 10000000000.0));
      var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.Support1));
      yData.SetYMapping(y => y);
      compositeDataSource = xData.Join(yData);
      return compositeDataSource;
    }
    public static CompositeDataSource R2(List<ResistanceSupport> resistanceSupportList)
    {
      if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
      CompositeDataSource compositeDataSource;
      var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
      xData.SetXMapping(x => (x.Ticks / 10000000000.0));
      var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.Resistance2));
      yData.SetYMapping(y => y);
      compositeDataSource = xData.Join(yData);
      return compositeDataSource;
    }
    public static CompositeDataSource S2(List<ResistanceSupport> resistanceSupportList)
    {
      if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
      CompositeDataSource compositeDataSource;
      var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
      xData.SetXMapping(x => (x.Ticks / 10000000000.0));
      var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.Support2));
      yData.SetYMapping(y => y);
      compositeDataSource = xData.Join(yData);
      return compositeDataSource;
    }
    public static CompositeDataSource High(List<ResistanceSupport> resistanceSupportList)
    {
      if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
      CompositeDataSource compositeDataSource;
      var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
      xData.SetXMapping(x => (x.Ticks / 10000000000.0));
      var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.High));
      yData.SetYMapping(y => y);
      compositeDataSource = xData.Join(yData);
      return compositeDataSource;
    }
    public static CompositeDataSource Low(List<ResistanceSupport> resistanceSupportList)
    {
      if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
      CompositeDataSource compositeDataSource;
      var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
      xData.SetXMapping(x => (x.Ticks / 10000000000.0));
      var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.Low));
      yData.SetYMapping(y => y);
      compositeDataSource = xData.Join(yData);
      return compositeDataSource;
    }
    public static CompositeDataSource Close(List<ResistanceSupport> resistanceSupportList)
    {
      if (null == resistanceSupportList || 0 == resistanceSupportList.Count) return null;
      CompositeDataSource compositeDataSource;
      var xData = new EnumerableDataSource<DateTime>(resistanceSupportList.Select(x => x.Date.Date));
      xData.SetXMapping(x => (x.Ticks / 10000000000.0));
      var yData = new EnumerableDataSource<double>(resistanceSupportList.Select(y => y.Close));
      yData.SetYMapping(y => y);
      compositeDataSource = xData.Join(yData);
      return compositeDataSource;
    }
  }
}
