/// <summary>
 /// JavaGenerator constructor
 /// </summary>
 /// <param name="model">Model representing metadata</param>
 public JavaGenerator(IEdmModel model)
 {
     CommonGenerator = new CommonGenerator(model);
 }
        /// <summary>
        /// Formulates the requested Graph snippets and returns it as string for JavaScript
        /// </summary>
        /// <param name="snippetModel">Model of the Snippets info <see cref="SnippetModel"/></param>
        /// <param name="languageExpressions">The language expressions to be used for code Gen</param>
        /// <returns>String of the snippet in Javascript code</returns>
        public static string GenerateCodeSnippet(SnippetModel snippetModel, LanguageExpressions languageExpressions)
        {
            try
            {
                var snippetBuilder = new StringBuilder();
                snippetModel.ResponseVariableName = CommonGenerator.EnsureVariableNameIsNotReserved(snippetModel.ResponseVariableName, languageExpressions);
                //setup the auth snippet section
                snippetBuilder.Append("const options = {\r\n");
                snippetBuilder.Append("\tauthProvider,\r\n};\r\n\r\n");
                //init the client
                snippetBuilder.Append("const client = Client.init(options);\r\n\r\n");

                if (snippetModel.Method == HttpMethod.Get)
                {
                    //append any queries with the actions
                    snippetBuilder.Append($"let {snippetModel.ResponseVariableName} = ");
                    var getActions = CommonGenerator.GenerateQuerySection(snippetModel, languageExpressions) + "\r\n\t.get();";
                    snippetBuilder.Append(GenerateRequestSection(snippetModel, getActions));
                }
                else if (snippetModel.Method == HttpMethod.Post)
                {
                    if (!string.IsNullOrEmpty(snippetModel.RequestBody))
                    {
                        snippetBuilder.Append(JavascriptGenerateObjectFromJson(snippetModel.RequestBody, snippetModel.ResponseVariableName));
                        snippetBuilder.Append(GenerateRequestSection(snippetModel, $"\r\n\t.post({snippetModel.ResponseVariableName});"));
                    }
                    else
                    {
                        snippetBuilder.Append(GenerateRequestSection(snippetModel, "\r\n\t.post();"));
                    }
                }
                else if (snippetModel.Method == HttpMethod.Patch)
                {
                    if (string.IsNullOrEmpty(snippetModel.RequestBody))
                    {
                        throw new ArgumentException("No body present for PATCH method in Javascript");
                    }

                    snippetBuilder.Append(JavascriptGenerateObjectFromJson(snippetModel.RequestBody, snippetModel.ResponseVariableName));
                    snippetBuilder.Append(GenerateRequestSection(snippetModel, $"\r\n\t.update({snippetModel.ResponseVariableName});"));
                }
                else if (snippetModel.Method == HttpMethod.Delete)
                {
                    snippetBuilder.Append(GenerateRequestSection(snippetModel, "\r\n\t.delete();"));
                }
                else if (snippetModel.Method == HttpMethod.Put)
                {
                    if (string.IsNullOrEmpty(snippetModel.RequestBody))
                    {
                        throw new ArgumentException("No body present for PUT method in Javascript");
                    }

                    snippetBuilder.Append(JavascriptGenerateObjectFromJson(snippetModel.RequestBody, snippetModel.ResponseVariableName));
                    snippetBuilder.Append(GenerateRequestSection(snippetModel, $"\r\n\t.put({snippetModel.ResponseVariableName});"));
                }
                else
                {
                    throw new NotImplementedException("HTTP method not implemented for Javascript");
                }

                return(snippetBuilder.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }