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

namespace PortfolioManager.Models
{
  public class InsiderTransactionModel
  {
    private InsiderTransactionModel()
    {
    }
    
    public static CompositeDataSource Empty()
    {
      CompositeDataSource compositeDataSource = new CompositeDataSource()
      {
          DataAdapter = new SortedDateTimeDataAdapter()
      };
      return compositeDataSource;
    }       
        
    public static CompositeDataSource InsiderTransactionSummaries(InsiderTransactionSummaries insiderTransactionSummaries, double minPrice)
    {
      if (null == insiderTransactionSummaries || 0 == insiderTransactionSummaries.Count) return Empty();
      SortedDateTimeDataAdapter sortedDateTimeDataAdapter = new SortedDateTimeDataAdapter();
      List<InsiderTransactionSummary> sortedInsiderTransactionSummaries = insiderTransactionSummaries.OrderBy(x => x.TransactionDate).ToList();
      foreach (InsiderTransactionSummary insiderTransactionSummary in sortedInsiderTransactionSummaries)
      {
        sortedDateTimeDataAdapter.Add(insiderTransactionSummary.TransactionDate, minPrice);
      }
      CompositeDataSource compositeDataSource = new CompositeDataSource()
      {
        DataAdapter = sortedDateTimeDataAdapter
      };
      return compositeDataSource;
    }
  }
}