using System;
using System.Collections.Generic;
using System.Text;
using MarketData.MarketDataModel;
using MarketData.DataAccess;
using MarketData.Utils;
using System.Linq;
using MarketData.Helper;
using MarketData.Numerical;

namespace MarketData.Generator.Momentum
{
  public class SlotPositions : List<SlotPosition>
  {
    public SlotPositions()
    {
    }
    public SlotPositions(int slot,Positions positions)
    {
      for(int index=0;index<positions.Count;index++)
      {
        Add(new SlotPosition(slot,positions[index]));
      }
    }
    public NVPCollections ToNVPCollections()
    {
      NVPCollections nvpCollections=new NVPCollections();
      foreach(SlotPosition position in this)
      {
        nvpCollections.Add(position.ToNVPCollection());
      }
      return nvpCollections;
    }
    public static SlotPositions FromNVPCollections(NVPCollections nvpCollections)
    {
      SlotPositions positions=new SlotPositions();
      foreach(NVPCollection nvpCollection in nvpCollections)
      {
        positions.Add(SlotPosition.FromNVPCollection(nvpCollection)); 
      }
      return positions;
    }
  }
  public class SlotPosition : Position
  {
    public SlotPosition()
    {
    }
    public SlotPosition(int slot,Position position) : base(position)
    {
      Slot=slot;
    }
    public SlotPosition(Position position) : base(position)
    {
    }
    public int Slot{get;set;}
    public Position ToPosition()
    {
      Position position = new Position(this);
      return position;
    }
    public override NVPCollection ToNVPCollection()
    {
      NVPCollection nvpCollection=base.ToNVPCollection();
      nvpCollection.Insert(0,new NVP("Slot",Slot.ToString()));
      return nvpCollection;
    }
    public static new SlotPosition FromNVPCollection(NVPCollection nvpCollection)
    {
      NVPDictionary nvpDictionary=nvpCollection.ToDictionary();
      Position position=Position.FromNVPCollection(nvpCollection);
      SlotPosition slotPosition=new SlotPosition(position);
      slotPosition.Slot=nvpDictionary["Slot"].Get<int>();
      return slotPosition;
    }
  }
}
