<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Core" #>
<#@ include file="Snippets/Index.tt" once="true" #>
/// <summary>
/// Retrieves a specific message from an agent conversation.
/// </summary>
internal sealed class <#= this.Name #>Executor(FormulaSession session, WorkflowAgentProvider agentProvider) : ActionExecutor(id: "<#= this.Id #>", session)
{
    // <inheritdoc />
    protected override async ValueTask<object?> ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)
    {<#
        EvaluateStringExpression(this.Model.ConversationId, "conversationId");
        EvaluateIntExpression(this.Model.Limit, "limit");
        EvaluateStringExpression(this.Model.MessageAfter, "after", isNullable: true);
        EvaluateStringExpression(this.Model.MessageBefore, "before", isNullable: true);
        EvaluateEnumExpression<AgentMessageSortOrderWrapper, bool>(this.Model.SortOrder, "newestFirst", SortMap, defaultValue: DefaultSort); #>
        IAsyncEnumerable<ChatMessage> messagesResult = 
            agentProvider.GetMessagesAsync(
                conversationId, 
                limit, 
                after,
                before,
                newestFirst,
                cancellationToken);
        List<ChatMessage> messages = [];
        await foreach (ChatMessage message in messagesResult.ConfigureAwait(false))
        {
            messages.Add(message);
        }<#
        AssignVariable(this.Model.Messages, "messages");
        #>
        return default;
    }
}