// ------------------------------------------------------------------------------
// <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 System;
    
    /// <summary>
    /// Class to produce the template output
    /// </summary>
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")]
    internal partial class ProviderTemplate : CodeTemplate
    {
        /// <summary>
        /// Create the template output
        /// </summary>
        public override string TransformText()
        {
            this.Write("\n");
            this.Write("\n");
            this.Write(@"
// ------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
// </auto-generated>
// ------------------------------------------------------------------------------

#nullable enable
#pragma warning disable IDE0005 // Extra using directive is ok.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Agents.AI.Workflows.Declarative;
using Microsoft.Agents.AI.Workflows.Declarative.Kit;
using Microsoft.Extensions.AI;
");

if (this.Namespace is not null) 
{
            this.Write("\nnamespace ");
            this.Write(this.ToStringHelper.ToStringWithCulture(this.Namespace));
            this.Write(";\n");

}

            this.Write(@"
/// <summary>
/// This class provides a factory method to create a <see cref=""Workflow"" /> instance.
/// </summary>
/// <remarks>
/// The workflow defined here was generated from a declarative workflow definition.
/// Declarative workflows utilize Power FX for defining conditions and expressions.
/// To learn more about Power FX, see:
/// https://learn.microsoft.com/power-platform/power-fx/formula-reference-copilot-studio
/// </remarks>
public static class ");
            this.Write(this.ToStringHelper.ToStringWithCulture(this.Prefix ?? string.Empty));
            this.Write("WorkflowProvider\n{");

foreach (string executor in ByLine(this.Executors, formatGroup: true))
{ 
            this.Write("\n    ");
            this.Write(this.ToStringHelper.ToStringWithCulture(executor));

}

            this.Write(@"
    public static Workflow CreateWorkflow<TInput>(
        DeclarativeWorkflowOptions options,
        Func<TInput, ChatMessage>? inputTransform = null) 
        where TInput : notnull
    {
        // Create root executor to initialize the workflow.
        inputTransform ??= (message) => DeclarativeWorkflowBuilder.DefaultTransform(message);
        ");
            this.Write(this.ToStringHelper.ToStringWithCulture(this.RootExecutorType));
            this.Write("Executor<TInput> ");
            this.Write(this.ToStringHelper.ToStringWithCulture(this.RootInstance));
            this.Write(" = new(options, inputTransform);");


        // Create executor instances
foreach (string instance in ByLine(this.Instances))
{ 
            this.Write("\n        ");
            this.Write(this.ToStringHelper.ToStringWithCulture(instance));

}
            this.Write("\n\n        // Define the workflow builder\n        WorkflowBuilder builder = new(");
            this.Write(this.ToStringHelper.ToStringWithCulture(this.RootInstance));
            this.Write(");\n\n        // Connect executors");

foreach (string edge in ByLine(this.Edges))
{ 
            this.Write("\n        ");
            this.Write(this.ToStringHelper.ToStringWithCulture(edge));

}
 
            this.Write("\n\n        // Build the workflow\n        return builder.Build(validateOrphans: fal" +
                    "se);\n    }\n}\n");
            return this.GenerationEnvironment.ToString();
        }
    }
}
