using System;
using System.Collections.Generic;

namespace MarketData.MarketDataModel
{
  public class DMAPricesByDate : Dictionary<DateTime, DMAPrice>
  {
    public DMAPricesByDate()
    {
    }
  }
  public class DMAValues : List<DMAValue>
  {
    public DMAValues()
    {
    }
    public float[] GetValues(int startIndex, int count)
    {
      if (startIndex + count > Count) return null;
      float[] valuesArray = new float[count];
      for (int index = startIndex, arrayIndex = 0; index < startIndex + count; index++, arrayIndex++)
      {
        valuesArray[arrayIndex] = (float)this[index].Value;
      }
      return valuesArray;
    }
  }
  public class DMAPrices : List<DMAPrice>
  {
    public DMAPrices()
    {
    }
    public DMAPrices(List<DMAPrice> dmaPrices)
    {
      foreach(DMAPrice dmaPrice in dmaPrices)Add(dmaPrice);
    }
    public DMAPrices Top(int count)
    {
      DMAPrices dmaPrices=new DMAPrices();
      for(int index=0;index<count&&index<Count;index++)
      {
        dmaPrices.Add(this[index]);
      }
      return dmaPrices;
    }
    public DMAPricesByDate GetDMAPricesByDate()
    {
      DMAPricesByDate dmaPricesByDate = new DMAPricesByDate();
      for (int index = 0; index < Count; index++)
      {
        DMAPrice dmaPrice = this[index];
        if (!dmaPricesByDate.ContainsKey(dmaPrice.Date))dmaPricesByDate.Add(dmaPrice.Date,dmaPrice);
      }
      return dmaPricesByDate;
    }
    public double[] GetAverages()
    {
      if(0==Count)return null;
      double[] averages=new double[Count];
      for(int index=0;index<Count;index++)averages[index]=this[index].AVGPrice;
      return averages;
    }
// new 10/27/2018
    public float[] GetReturns()
    {
      if(Count==0||1==Count)return null;
      float[] returns = new float[Count - 1];
      for (int index = 0; index < Count - 1; index++)
      {
        double currentPrice = this[index].AVGPrice;
        double prevPrice = this[index + 1].AVGPrice;
        if (0.00 == prevPrice) returns[index] = 0.00F;
        else returns[index] = (float)((currentPrice - prevPrice) / Math.Abs(prevPrice));
      }
      return returns;
    }
  }
  public class DMAValue
  {
    private DateTime date;
    private double value;
    private double maValue;

    public DMAValue()
    {
    }
    public DMAValue(DateTime date, double value)
    {
      this.date = date;
      this.value = value;
    }
    public DateTime Date
    {
      get { return date; }
      set { date = value; }
    }
    public double Value
    {
      get { return value; }
      set { this.value = value; }
    }
    public double MAValue
    {
      get { return maValue; }
      set { this.maValue = value; }
    }
  }
  public class DMAPrice
  {
    private String symbol;
    private DateTime date;
    private double avgPrice;
    private double minPrice;
    private double maxPrice;
    private double currentPrice;
    public DMAPrice()
    {
    }
    public String Symbol
    {
      get { return symbol; }
      set { symbol = value; }
    }
    public DateTime Date
    {
      get { return date; }
      set { date = value; }
    }
    public double AVGPrice
    {
      get { return avgPrice; }
      set { avgPrice = value; }
    }
    public double MinPrice
    {
      get { return minPrice; }
      set { minPrice = value; }
    }
    public double MaxPrice
    {
      get { return maxPrice; }
      set { maxPrice = value; }
    }
    public double CurrentPrice
    {
      get { return currentPrice; }
      set { currentPrice = value; }
    }
  }
}
