# Copyright (c) Microsoft. All rights reserved.

"""Workflow fixtures for hosting tests.

Defined in a module that does not use ``from __future__ import annotations``
because the workflow handler validation reflects on real annotation objects
rather than stringified forms.
"""

from typing import Any

from agent_framework import Executor, Workflow, WorkflowBuilder, WorkflowContext, handler


class _UpperExecutor(Executor):
    @handler
    async def handle(self, text: str, ctx: WorkflowContext[Any, str]) -> None:
        await ctx.yield_output(text.upper())


class _EchoExecutor(Executor):
    @handler
    async def handle(self, text: str, ctx: WorkflowContext[Any, str]) -> None:
        await ctx.yield_output(text)


def build_upper_workflow() -> Workflow:
    return WorkflowBuilder(start_executor=_UpperExecutor(id="upper")).build()


def build_echo_workflow() -> Workflow:
    return WorkflowBuilder(start_executor=_EchoExecutor(id="echo")).build()


def echo_workflow_builder() -> WorkflowBuilder:
    """Return an *unbuilt* echo ``WorkflowBuilder``, for testing builder-shaped targets."""
    return WorkflowBuilder(start_executor=_EchoExecutor(id="echo"))


class _MultiChunkExecutor(Executor):
    """Yields three separate ``output`` events so streaming has something to chew on."""

    @handler
    async def handle(self, text: str, ctx: WorkflowContext[Any, str]) -> None:
        for chunk in (f"{text}-1", f"{text}-2", f"{text}-3"):
            await ctx.yield_output(chunk)


def build_multi_chunk_workflow() -> Workflow:
    return WorkflowBuilder(start_executor=_MultiChunkExecutor(id="multi")).build()
