"""
This type stub file was generated by pyright.
"""

import concurrent.futures
import temporalio.client
import temporalio.converter
import temporalio.runtime
from contextlib import asynccontextmanager
from dataclasses import dataclass
from typing import AsyncIterator, Mapping, Optional, Sequence, Type
from typing_extensions import TypedDict
from ._interceptor import Interceptor
from ._workflow_instance import WorkflowRunner

"""Replayer."""
logger = ...
class Replayer:
    """Replayer to replay workflows from history."""
    def __init__(self, *, workflows: Sequence[Type], workflow_task_executor: Optional[concurrent.futures.ThreadPoolExecutor] = ..., workflow_runner: WorkflowRunner = ..., unsandboxed_workflow_runner: WorkflowRunner = ..., namespace: str = ..., data_converter: temporalio.converter.DataConverter = ..., interceptors: Sequence[Interceptor] = ..., build_id: Optional[str] = ..., identity: Optional[str] = ..., debug_mode: bool = ..., runtime: Optional[temporalio.runtime.Runtime] = ...) -> None:
        """Create a replayer to replay workflows from history.

        See :py:meth:`temporalio.worker.Worker.__init__` for a description of
        most of the arguments. The same arguments need to be passed to the
        replayer that were passed to the worker when the workflow originally
        ran.
        """
        ...
    
    def config(self) -> ReplayerConfig:
        """Config, as a dictionary, used to create this replayer.

        Returns:
            Configuration, shallow-copied.
        """
        ...
    
    async def replay_workflow(self, history: temporalio.client.WorkflowHistory, *, raise_on_replay_failure: bool = ...) -> WorkflowReplayResult:
        """Replay a workflow for the given history.

        Args:
            history: The history to replay. Can be fetched directly, or use
                :py:meth:`temporalio.client.WorkflowHistory.from_json` to parse
                a history downloaded via ``tctl`` or the web UI.
            raise_on_replay_failure: If ``True`` (the default), this will raise
                a :py:attr:`WorkflowReplayResult.replay_failure` if it is
                present.
        """
        ...
    
    async def replay_workflows(self, histories: AsyncIterator[temporalio.client.WorkflowHistory], *, raise_on_replay_failure: bool = ...) -> WorkflowReplayResults:
        """Replay workflows for the given histories.

        This is a shortcut for :py:meth:`workflow_replay_iterator` that iterates
        all results and aggregates information about them.

        Args:
            histories: The histories to replay, from an async iterator.
            raise_on_replay_failure: If ``True`` (the default), this will raise
                the first replay failure seen.

        Returns:
            Aggregated results.
        """
        ...
    
    @asynccontextmanager
    async def workflow_replay_iterator(self, histories: AsyncIterator[temporalio.client.WorkflowHistory]) -> AsyncIterator[AsyncIterator[WorkflowReplayResult]]:
        """Replay workflows for the given histories.

        This is a context manager for use via ``async with``. The value is an
        iterator for use via ``async for``.

        Args:
            histories: The histories to replay, from an async iterator.

        Returns:
            An async iterator that returns replayed workflow results as they are
            replayed.
        """
        ...
    


class ReplayerConfig(TypedDict, total=False):
    """TypedDict of config originally passed to :py:class:`Replayer`."""
    workflows: Sequence[Type]
    workflow_task_executor: Optional[concurrent.futures.ThreadPoolExecutor]
    workflow_runner: WorkflowRunner
    unsandboxed_workflow_runner: WorkflowRunner
    namespace: str
    data_converter: temporalio.converter.DataConverter
    interceptors: Sequence[Interceptor]
    build_id: Optional[str]
    identity: Optional[str]
    debug_mode: bool
    runtime: Optional[temporalio.runtime.Runtime]
    ...


@dataclass(frozen=True)
class WorkflowReplayResult:
    """Single workflow replay result."""
    history: temporalio.client.WorkflowHistory
    replay_failure: Optional[Exception]
    ...


@dataclass(frozen=True)
class WorkflowReplayResults:
    """Results of replaying multiple workflows."""
    replay_failures: Mapping[str, Exception]
    ...


