using System;
using System.Text;
using MarketData.Utils;

namespace MarketData.MarketDataModel
{
  public class ModelTrade
  {
    public enum TradeType { Buy, Sell };
    private DateTime tradeDate;
    private String symbol;
    private int shares;
    private double price;
    private TradeType tradeType;
    private int daysHeld;
    private double gainLoss;
    private double exposure;
    private double returnOnPosition;
    private String comment;

    public ModelTrade()
    {
    }
    public String Symbol
    {
      get { return symbol; }
      set { symbol = value; }
    }
    public DateTime TradeDate
    {
      get { return tradeDate; }
      set { tradeDate = value; }
    }
    public int Shares
    {
      get { return shares; }
      set { shares = value; }
    }
    public double Price
    {
      get { return price; }
      set { price = value; }
    }
    public int DaysHeld
    {
      get { return daysHeld; }
      set { daysHeld = value; }
    }
    public double GainLoss
    {
      get { return gainLoss; }
      set { gainLoss = value; }
    }
    public double Return
    {
      get { return returnOnPosition; }
      set { returnOnPosition = value; }
    }
    public double Exposure
    {
      get { return exposure; }
      set { exposure = value; }
    }
    public String Comment
    {
      get { return comment; }
      set { comment = value; }
    }
    public ModelTrade.TradeType Type
    {
      get { return tradeType; }
      set { tradeType = value; }
    }
    public static String Header
    {
      get
      {
        return "Date,Buy/Sell,Symbol,Shares,Price,Gain/Loss,Days Held,Comment";
      }
    }
    public override string ToString()
    {
      StringBuilder sb = new StringBuilder();
      sb.Append(Utility.DateTimeToStringMMSDDSYYYY(TradeDate)).Append(",");
      sb.Append(tradeType.Equals(ModelTrade.TradeType.Sell) ? "Sell" : "Buy").Append(",");
      sb.Append(Symbol).Append(",");
      sb.Append(Shares).Append(",");
      sb.Append("\"" + String.Format("{0:C}", price) + "\"").Append(",");
      sb.Append("\"" + String.Format("{0:C}", gainLoss) + "\"").Append(",");
      sb.Append(daysHeld).Append(",");
      sb.Append("\"").Append(null!=comment?comment:"").Append("\"");
      return sb.ToString();
    }
  }
}