<#@ template language="C#" inherits="CodeTemplate" visibility="internal" linePragmas="false" #>
<#@ import namespace="Microsoft.Agents.AI.Workflows.Declarative.Extensions" #>
<#@ assembly name="System.Core" #>
// ------------------------------------------------------------------------------
// <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) 
{#>
namespace <#= this.Namespace #>;
<#
}
#>
/// <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.Prefix ?? string.Empty #>WorkflowProvider
{<#
foreach (string executor in ByLine(this.Executors, formatGroup: true))
{ #>
    <#= executor #><#
}
#>
    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.RootExecutorType #>Executor<TInput> <#= this.RootInstance #> = new(options, inputTransform);<#

        // Create executor instances
foreach (string instance in ByLine(this.Instances))
{ #>
        <#= instance #><#
}#>

        // Define the workflow builder
        WorkflowBuilder builder = new(<#= this.RootInstance #>);

        // Connect executors<#
foreach (string edge in ByLine(this.Edges))
{ #>
        <#= edge #><#
}
 #>

        // Build the workflow
        return builder.Build(validateOrphans: false);
    }
}
