///// <summary>
        ///// Builds the market.
        ///// </summary>
        ///// <param name="market">The market.</param>
        ///// <param name="pricingStructureTerms">The pricing structure terms.</param>
        ///// <param name="resultsContainer">The results container.</param>
        ///// <returns></returns>
        //public static IMarketEnvironment BuildMarket(string market, IDictionary<string, IDictionary<string, object>> pricingStructureTerms, NamedValueSet resultsContainer)
        //{
        //    const string cLowerRateCurve = "ratecurve";
        //    const string cLowerFXCurve = "fxcurve";
        //    const string cLowerVolSurface = "ratevolatilitymatrix";
        //    const string cLowerVolCube = "ratevolatilitycube";
        //    const string cPricingStructureTypeKey = CurveProp.PricingStructureType;

        //    IDictionary<string, List<string>> curveTOLegRefMap = new Dictionary<string, List<string>>();
        //    IDictionary<string, IRateCurveTerms> rateCurveTOCurveTermsMap = new Dictionary<string, IRateCurveTerms>();
        //    IDictionary<string, IFXCurveTerms> fxCurveTOCurveTermsMap = new Dictionary<string, IFXCurveTerms>();
        //    IDictionary<string, IVolatilitySurfaceTerms> volSurfaceTOSurfaceTermsMap = new Dictionary<string, IVolatilitySurfaceTerms>();
        //    IDictionary<string, IVolatilitySurfaceTerms> volCubeTOCubeTermsMap = new Dictionary<string, IVolatilitySurfaceTerms>();

        //    foreach (string pricingStructureTermsRef in pricingStructureTerms.Keys)
        //    {
        //        IDictionary<string, object> termProps = pricingStructureTerms[pricingStructureTermsRef];

        //        if (termProps == null) continue;
        //        var propKeys = new List<string>(termProps.Keys);

        //        string psTypeKey = propKeys.Find(item => string.Compare(item, cPricingStructureTypeKey, true) == 0);

        //        if (string.IsNullOrEmpty(psTypeKey))
        //        {
        //            continue;
        //        }

        //        IPricingStructureTerms curveTerms;
        //        switch (termProps[psTypeKey].ToString().ToLowerInvariant())
        //        {
        //            case cLowerRateCurve:
        //                curveTerms = new RateCurveTerms(termProps);
        //                UpdateMap(pricingStructureTermsRef, (IRateCurveTerms)curveTerms, rateCurveTOCurveTermsMap, curveTOLegRefMap, curveTerms.ReferenceKey);
        //                break;
        //            case cLowerFXCurve:
        //                curveTerms = new FXCurveTerms(termProps);
        //                UpdateMap(pricingStructureTermsRef, (IFXCurveTerms)curveTerms, fxCurveTOCurveTermsMap, curveTOLegRefMap, curveTerms.ReferenceKey);
        //                break;
        //            case cLowerVolSurface:
        //                curveTerms = new VolatilitySurfaceTerms(termProps);
        //                UpdateMap(pricingStructureTermsRef, (VolatilitySurfaceTerms)curveTerms, volSurfaceTOSurfaceTermsMap, curveTOLegRefMap, curveTerms.ReferenceKey);
        //                break;
        //            case cLowerVolCube:
        //                curveTerms = new VolatilitySurfaceTerms(termProps);
        //                UpdateMap(pricingStructureTermsRef, (VolatilitySurfaceTerms)curveTerms, volCubeTOCubeTermsMap, curveTOLegRefMap, curveTerms.ReferenceKey);
        //                break;
        //        }
        //    }
        //    IMarketEnvironment marketEnvironment = Create(market, rateCurveTOCurveTermsMap, fxCurveTOCurveTermsMap, volSurfaceTOSurfaceTermsMap, volCubeTOCubeTermsMap, curveTOLegRefMap);
        //    if (marketEnvironment != null)
        //    {
        //        IDictionary<string, IPricingStructure> structures = marketEnvironment.GetPricingStructures();
        //        resultsContainer.Add(ParsePricingStructures(structures));
        //    }
        //    return marketEnvironment;
        //}

        /// <summary>
        /// Validates the market.
        /// </summary>
        /// <param name="pricingStructures"></param>
        /// <param name="market"></param>
        public static void ValidateMarket(string[] pricingStructures, IMarketEnvironment market)
        {
            var missingStructures = new List <string>();

            if (market == null)
            {
                throw new ArgumentNullException(nameof(market), "A valid market has not been supplied");
            }
            IDictionary <string, IPricingStructure> ps = market.GetPricingStructures();

            if (market != null && ps.Count == 0)
            {
                throw new ApplicationException($"{market.Id} market does not contain any curves");
            }
            if (ps.Count <= 0)
            {
            }
            else
            {
                missingStructures.AddRange(pricingStructures.Where(structure => !StructureExists(ps, structure)));
                if (missingStructures.Count > 0)
                {
                    throw new ApplicationException(
                              $"{string.Join(", ", missingStructures.ToArray())} curves not found in {market.Id} market");
                }
            }
        }
 /// <summary>
 /// Structures the exists.
 /// </summary>
 /// <param name="marketEnvironment">The market environment.</param>
 /// <param name="name">The name.</param>
 /// <returns></returns>
 internal static Boolean StructureExists(IMarketEnvironment marketEnvironment, string name)
 {
     return(StructureExists(marketEnvironment.GetPricingStructures(), name));
 }