using MarketData.Configuration;
using Microsoft.Extensions.Configuration;

namespace MarketData.DataAccess
{
  public class MainDataSource
  {
    private Dictionary<String,DataSourceEx> dataSourceDictionary = new Dictionary<String,DataSourceEx>();
    private static MainDataSource mainDataSource;

    private MainDataSource()
    {
    }

    public static MainDataSource Instance
    {
      get
      {
        lock (typeof(MainDataSource))
        {
          if (null == mainDataSource)
          {
            mainDataSource = new MainDataSource();

            IConfiguration configuration = GlobalConfig.Instance.Configuration;
            DataSourceEx marketDataSource = new DataSourceEx(configuration, "market_data");
            mainDataSource.dataSourceDictionary.Add("market_data",marketDataSource);

            DataSourceEx portfolioDataSource = new DataSourceEx(configuration, "portfolio_data");
            mainDataSource.dataSourceDictionary.Add("portfolio_data",portfolioDataSource);

            DataSourceEx userDataSource = new DataSourceEx(configuration, "user_data");
            mainDataSource.dataSourceDictionary.Add("user_data",userDataSource);            
          }
          return mainDataSource;
        }
      }
    }

    public DataSourceEx LocateDataSource(String sourceKey)
    {
      return mainDataSource.dataSourceDictionary[sourceKey];
    }
  }
}
