using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Eremex.AvaloniaUI.Charts;
using MarketData.MarketDataModel;
using PortfolioManager.DataSeriesViewModels;

namespace PortfolioManager.Models
{
  public class PortfolioTradeModel
  {

    private PortfolioTradeModel()
    {
    }
    
    public static CompositeDataSource Empty()
    {
        CompositeDataSource compositeDataSource = new CompositeDataSource()
        {
            DataAdapter = new SortedDateTimeDataAdapter()
        };
        return compositeDataSource;
    }    

    public static CompositeDataSource PortfolioTrades(PortfolioTrades portfolioTrades)
    {
      if (null == portfolioTrades || 0 == portfolioTrades.Count) return Empty();
      List<PortfolioTrade> sortedPortfolioTrades = portfolioTrades.OrderBy(x => x.TradeDate).ToList();
      SortedDateTimeDataAdapter sortedDateTimeDataAdapter = new SortedDateTimeDataAdapter();
      foreach (PortfolioTrade portfolioTrade in sortedPortfolioTrades)
      {
        sortedDateTimeDataAdapter.Add(portfolioTrade.TradeDate, portfolioTrade.Price);
      }

      CompositeDataSource compositeDataSource = new CompositeDataSource()
      {
        DataAdapter = sortedDateTimeDataAdapter
      };
      return compositeDataSource;
    }
  }
}