using System;
using System.Collections.Generic;
using MarketData.Utils;

namespace MarketData.MarketDataModel.GainLoss
{
// *********************************************************************************************************************************************************************
// ************************************************************************  G A I N  L O S S **************************************************************************
// *********************************************************************************************************************************************************************
//  This gain loss provides a picture of the Active Gain/Loss.  The gain loss on open positions
  public class GainLossItem : IComparable
  {
    private DateTime date;
    private double gainLoss;
    private double gainLossPercent;
    private double exposure;
    private double dividends;
    private bool valueIsPercent;
    public GainLossItem()
    {
    }
    public GainLossItem(DateTime date, double gainLoss,double exposure,bool valueIsPercent)
    {
      this.date = date;
      this.gainLoss = gainLoss;
      this.exposure = exposure;
      this.valueIsPercent = valueIsPercent;
    }
    public GainLossItem(DateTime date, double gainLoss,double gainLossPercent,double exposure,bool valueIsPercent)
    {
      this.date = date;
      this.gainLoss = gainLoss;
      this.gainLossPercent=gainLossPercent;
      this.exposure = exposure;
      this.valueIsPercent = valueIsPercent;
    }
    public GainLossItem(DateTime date, double gainLoss,double gainLossPercent,double exposure,double dividends,bool valueIsPercent)
    {
      this.date = date;
      this.gainLoss = gainLoss;
      this.gainLossPercent=gainLossPercent;
      this.exposure = exposure;
      this.dividends=dividends;
      this.valueIsPercent = valueIsPercent;
    }
    public DateTime Date
    {
      get { return date; }
    }
    public double Exposure
    {
      get
      {
        return exposure;
      }
    }
    public double GainLoss
    {
      get { return gainLoss; }
    }
    public double Dividends
    {
      get{return dividends;}
    }
    public double GainLossPercent
    {
      get { return gainLossPercent; }
    }
    public bool ValueIsPercent
    {
      get
      {
        return valueIsPercent;
      }
      set
      {
        valueIsPercent = value;
      }
    }
    public String FormattedGainLoss
    {
      get
      {
        if (valueIsPercent) return Utility.FormatNumber(gainLoss);
        return Utility.FormatCurrency(gainLoss);
      }
    }
    public int CompareTo(Object obj)
    {
      if (!obj.GetType().IsInstanceOfType(this)) throw new Exception("Expected GainLoss");
      GainLossItem that = (GainLossItem)obj;
      return date.CompareTo(that.Date);
    }
  }
  public class GainLossCollection : List<GainLossItem>
  {
    public GainLossCollection(ICollection<GainLossItem> gainLoss)
      : base(gainLoss)
    {
    }
    public DMAValues DMAValues
    {
      get
      {
        DMAValues dmaValues = new DMAValues();
        foreach (GainLossItem gainLoss in this)
        {
          dmaValues.Add(new DMAValue(gainLoss.Date,gainLoss.GainLoss));
        }
        return dmaValues;
      }
    }
  }
}
