// ------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version: 18.0.0.0
//  
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen
{
    using Microsoft.Agents.AI.Workflows.Declarative.Extensions;
    using Microsoft.Agents.AI.Workflows.Declarative.Interpreter;
    using Microsoft.Bot.ObjectModel;
    using System;
    
    /// <summary>
    /// Class to produce the template output
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")]
    internal partial class RootTemplate : CodeTemplate, IModeledAction
    {
        /// <summary>
        /// Create the template output
        /// </summary>
        public override string TransformText()
        {
            this.Write("\n");
            this.Write("\n");
            this.Write("\n");
            this.Write("\n");
            this.Write("\n/// <summary>\n/// The root executor for a declarative workflow.\n/// </summary>\ni" +
                    "nternal sealed class ");
            this.Write(this.ToStringHelper.ToStringWithCulture(this.TypeName));
            this.Write("Executor<TInput>(\n    DeclarativeWorkflowOptions options,\n    Func<TInput, ChatMe" +
                    "ssage> inputTransform) :\n    RootExecutor<TInput>(\"");
            this.Write(this.ToStringHelper.ToStringWithCulture(this.Id));
            this.Write("\", options, inputTransform)\n    where TInput : notnull\n{\n    protected override a" +
                    "sync ValueTask ExecuteAsync(TInput message, IWorkflowContext context, Cancellati" +
                    "onToken cancellationToken)\n    {");
 
if (this.TypeInfo.EnvironmentVariables.Count > 0)
{ 
            this.Write("\n        // Set environment variables\n        await this.InitializeEnvironmentAsy" +
                    "nc(\n            context,");

    int index = this.TypeInfo.EnvironmentVariables.Count - 1;
    foreach (string variableName in this.TypeInfo.EnvironmentVariables)
    {
            this.Write("\n            \"");
            this.Write(this.ToStringHelper.ToStringWithCulture(variableName));
            this.Write("\"");
            this.Write(this.ToStringHelper.ToStringWithCulture(index > 0 ? "," : ""));

        --index;
    }
            this.Write(").ConfigureAwait(false);\n");
}

if (this.TypeInfo.UserVariables.Count > 0)
{ 

            this.Write("\n        // Initialize variables");

    foreach (VariableInformationDiagnostic variableInfo in this.TypeInfo.UserVariables)
    {
            this.Write("\n        await context.QueueStateUpdateAsync(\"");
            this.Write(this.ToStringHelper.ToStringWithCulture(variableInfo.Path.VariableName));
            this.Write("\", UnassignedValue.Instance, \"");
            this.Write(this.ToStringHelper.ToStringWithCulture(variableInfo.Path.NamespaceAlias));
            this.Write("\").ConfigureAwait(false);");

    }
}
            this.Write("\n    }\n}\n");
            return this.GenerationEnvironment.ToString();
        }
    }
}
