using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.ObjectModel;
using System.Text;
using MarketData.ValueAtRisk;
using MarketData.DataAccess;

namespace TradeBlotter.ViewModels
{
  public class PortfolioHoldingsViewModelCollectionHelper
  {
    private PortfolioHoldingsViewModelCollectionHelper()
    {
    }
    public static ObservableCollection<PortfolioHoldingViewModel> CreateCollection(PortfolioHoldings portfolioHoldings)
    {
      ObservableCollection<PortfolioHoldingViewModel> collection = new ObservableCollection<PortfolioHoldingViewModel>();
      foreach (PortfolioHolding portfolioHolding in portfolioHoldings) collection.Add(new PortfolioHoldingViewModel(portfolioHolding));
      collection=new ObservableCollection<PortfolioHoldingViewModel>(collection.OrderByDescending(x=>x.Contribution).ToList());
      return collection;
    }
    public static PortfolioHoldings CreateCollection(ObservableCollection<PortfolioHoldingViewModel> portfolioHoldingViewModelCollection)
    {
      PortfolioHoldings portfolioHoldings = new PortfolioHoldings();
      foreach (PortfolioHoldingViewModel portfolioHoldingViewModel in portfolioHoldingViewModelCollection) portfolioHoldings.Add(portfolioHoldingViewModel);
      return portfolioHoldings;
    }
  }
  public class PortfolioHoldingViewModel : PortfolioHolding
  {
    private String sector;
    private String industry;
    private bool isSelected;

    public PortfolioHoldingViewModel(PortfolioHolding portfolioHolding)
      : base(portfolioHolding)
    {
      try
      {
        sector = PricingDA.GetSectorForSymbol(portfolioHolding.Symbol);
        if(null==sector||"".Equals(sector))sector="Unclassified";
        industry = PricingDA.GetIndustryForSymbol(portfolioHolding.Symbol);
        if(null==industry||"".Equals(industry))industry="Unclassified";
      }
      finally
      {
      }
    }
    public String Sector
    {
      get { return sector; }
      set { sector = value; }
    }
    public String Industry
    {
      get { return industry; }
      set { industry = value; }
    }
    public bool IsSelected
    {
      get { return isSelected; }
      set { isSelected = value; }
    }
  }
}
