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

import json
import sys
import temporalio.api.common.v1
import temporalio.api.failure.v1
import temporalio.common
import temporalio.types
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Any, ClassVar, List, Mapping, NewType, Optional, Sequence, Tuple, Type, Union, overload

"""
This type stub file was generated by pyright.
"""
if sys.version_info < (3, 11):
    ...
if sys.version_info >= (3, 11):
    ...
if sys.version_info >= (3, 10):
    ...
class PayloadConverter(ABC):
    """Base payload converter to/from multiple payloads/values."""
    default: ClassVar[PayloadConverter]
    @abstractmethod
    def to_payloads(self, values: Sequence[Any]) -> List[temporalio.api.common.v1.Payload]:
        """Encode values into payloads.

        Implementers are expected to just return the payload for
        :py:class:`temporalio.common.RawValue`.

        Args:
            values: Values to be converted.

        Returns:
            Converted payloads. Note, this does not have to be the same number
            as values given, but must be at least one and cannot be more than
            was given.

        Raises:
            Exception: Any issue during conversion.
        """
        ...
    
    @abstractmethod
    def from_payloads(self, payloads: Sequence[temporalio.api.common.v1.Payload], type_hints: Optional[List[Type]] = ...) -> List[Any]:
        """Decode payloads into values.

        Implementers are expected to treat a type hint of
        :py:class:`temporalio.common.RawValue` as just the raw value.

        Args:
            payloads: Payloads to convert to Python values.
            type_hints: Types that are expected if any. This may not have any
                types if there are no annotations on the target. If this is
                present, it must have the exact same length as payloads even if
                the values are just "object".

        Returns:
            Collection of Python values. Note, this does not have to be the same
            number as values given, but at least one must be present.

        Raises:
            Exception: Any issue during conversion.
        """
        ...
    
    def to_payloads_wrapper(self, values: Sequence[Any]) -> temporalio.api.common.v1.Payloads:
        """:py:meth:`to_payloads` for the
        :py:class:`temporalio.api.common.v1.Payloads` wrapper.
        """
        ...
    
    def from_payloads_wrapper(self, payloads: Optional[temporalio.api.common.v1.Payloads]) -> List[Any]:
        """:py:meth:`from_payloads` for the
        :py:class:`temporalio.api.common.v1.Payloads` wrapper.
        """
        ...
    
    def to_payload(self, value: Any) -> temporalio.api.common.v1.Payload:
        """Convert a single value to a payload.

        This is a shortcut for :py:meth:`to_payloads` with a single-item list
        and result.

        Args:
            value: Value to convert to a single payload.

        Returns:
            Single converted payload.
        """
        ...
    
    @overload
    def from_payload(self, payload: temporalio.api.common.v1.Payload) -> Any:
        ...
    
    @overload
    def from_payload(self, payload: temporalio.api.common.v1.Payload, type_hint: Type[temporalio.types.AnyType]) -> temporalio.types.AnyType:
        ...
    
    def from_payload(self, payload: temporalio.api.common.v1.Payload, type_hint: Optional[Type] = ...) -> Any:
        """Convert a single payload to a value.

        This is a shortcut for :py:meth:`from_payloads` with a single-item list
        and result.

        Args:
            payload: Payload to convert to value.
            type_hint: Optional type hint to say which type to convert to.

        Returns:
            Single converted value.
        """
        ...
    


class EncodingPayloadConverter(ABC):
    """Base converter to/from single payload/value with a known encoding for use in CompositePayloadConverter."""
    @property
    @abstractmethod
    def encoding(self) -> str:
        """Encoding for the payload this converter works with."""
        ...
    
    @abstractmethod
    def to_payload(self, value: Any) -> Optional[temporalio.api.common.v1.Payload]:
        """Encode a single value to a payload or None.

        Args:
            value: Value to be converted.

        Returns:
            Payload of the value or None if unable to convert.

        Raises:
            TypeError: Value is not the expected type.
            ValueError: Value is of the expected type but otherwise incorrect.
            RuntimeError: General error during encoding.
        """
        ...
    
    @abstractmethod
    def from_payload(self, payload: temporalio.api.common.v1.Payload, type_hint: Optional[Type] = ...) -> Any:
        """Decode a single payload to a Python value or raise exception.

        Args:
            payload: Payload to convert to Python value.
            type_hint: Type that is expected if any. This may not have a type if
                there are no annotations on the target.

        Return:
            The decoded value from the payload. Since the encoding is checked by
            the caller, this should raise an exception if the payload cannot be
            converted.

        Raises:
            RuntimeError: General error during decoding.
        """
        ...
    


class CompositePayloadConverter(PayloadConverter):
    """Composite payload converter that delegates to a list of encoding payload converters.

    Encoding/decoding are attempted on each payload converter successively until
    it succeeds.

    Attributes:
        converters: List of payload converters to delegate to, in order.
    """
    converters: Mapping[bytes, EncodingPayloadConverter]
    def __init__(self, *converters: EncodingPayloadConverter) -> None:
        """Initializes the data converter.

        Args:
            converters: Payload converters to delegate to, in order.
        """
        ...
    
    def to_payloads(self, values: Sequence[Any]) -> List[temporalio.api.common.v1.Payload]:
        """Encode values trying each converter.

        See base class. Always returns the same number of payloads as values.

        Raises:
            RuntimeError: No known converter
        """
        ...
    
    def from_payloads(self, payloads: Sequence[temporalio.api.common.v1.Payload], type_hints: Optional[List[Type]] = ...) -> List[Any]:
        """Decode values trying each converter.

        See base class. Always returns the same number of values as payloads.

        Raises:
            KeyError: Unknown payload encoding
            RuntimeError: Error during decode
        """
        ...
    


class DefaultPayloadConverter(CompositePayloadConverter):
    """Default payload converter compatible with other Temporal SDKs.

    This handles None, bytes, all protobuf message types, and any type that
    :py:func:`json.dump` accepts. A singleton instance of this is available at
    :py:attr:`PayloadConverter.default`.
    """
    default_encoding_payload_converters: Tuple[EncodingPayloadConverter, ...]
    def __init__(self) -> None:
        """Create a default payload converter."""
        ...
    


class BinaryNullPayloadConverter(EncodingPayloadConverter):
    """Converter for 'binary/null' payloads supporting None values."""
    @property
    def encoding(self) -> str:
        """See base class."""
        ...
    
    def to_payload(self, value: Any) -> Optional[temporalio.api.common.v1.Payload]:
        """See base class."""
        ...
    
    def from_payload(self, payload: temporalio.api.common.v1.Payload, type_hint: Optional[Type] = ...) -> Any:
        """See base class."""
        ...
    


class BinaryPlainPayloadConverter(EncodingPayloadConverter):
    """Converter for 'binary/plain' payloads supporting bytes values."""
    @property
    def encoding(self) -> str:
        """See base class."""
        ...
    
    def to_payload(self, value: Any) -> Optional[temporalio.api.common.v1.Payload]:
        """See base class."""
        ...
    
    def from_payload(self, payload: temporalio.api.common.v1.Payload, type_hint: Optional[Type] = ...) -> Any:
        """See base class."""
        ...
    


_sym_db = ...
class JSONProtoPayloadConverter(EncodingPayloadConverter):
    """Converter for 'json/protobuf' payloads supporting protobuf Message values."""
    def __init__(self, ignore_unknown_fields: bool = ...) -> None:
        """Initialize a JSON proto converter.

        Args:
            ignore_unknown_fields: Determines whether converter should error if
                unknown fields are detected
        """
        ...
    
    @property
    def encoding(self) -> str:
        """See base class."""
        ...
    
    def to_payload(self, value: Any) -> Optional[temporalio.api.common.v1.Payload]:
        """See base class."""
        ...
    
    def from_payload(self, payload: temporalio.api.common.v1.Payload, type_hint: Optional[Type] = ...) -> Any:
        """See base class."""
        ...
    


class BinaryProtoPayloadConverter(EncodingPayloadConverter):
    """Converter for 'binary/protobuf' payloads supporting protobuf Message values."""
    @property
    def encoding(self) -> str:
        """See base class."""
        ...
    
    def to_payload(self, value: Any) -> Optional[temporalio.api.common.v1.Payload]:
        """See base class."""
        ...
    
    def from_payload(self, payload: temporalio.api.common.v1.Payload, type_hint: Optional[Type] = ...) -> Any:
        """See base class."""
        ...
    


class AdvancedJSONEncoder(json.JSONEncoder):
    """Advanced JSON encoder.

    This encoder supports dataclasses, classes with dict() functions, and
    all iterables as lists.
    """
    def default(self, o: Any) -> Any:
        """Override JSON encoding default.

        See :py:meth:`json.JSONEncoder.default`.
        """
        ...
    


class JSONPlainPayloadConverter(EncodingPayloadConverter):
    """Converter for 'json/plain' payloads supporting common Python values.

    For encoding, this supports all values that :py:func:`json.dump` supports
    and by default adds extra encoding support for dataclasses, classes with
    ``dict()`` methods, and all iterables.

    For decoding, this uses type hints to attempt to rebuild the type from the
    type hint.
    """
    _encoder: Optional[Type[json.JSONEncoder]]
    _decoder: Optional[Type[json.JSONDecoder]]
    _encoding: str
    def __init__(self, *, encoder: Optional[Type[json.JSONEncoder]] = ..., decoder: Optional[Type[json.JSONDecoder]] = ..., encoding: str = ..., custom_type_converters: Sequence[JSONTypeConverter] = ...) -> None:
        """Initialize a JSON data converter.

        Args:
            encoder: Custom encoder class object to use.
            decoder: Custom decoder class object to use.
            encoding: Encoding name to use.
            custom_type_converters: Set of custom type converters that are used
                when converting from a payload to type-hinted values.
        """
        ...
    
    @property
    def encoding(self) -> str:
        """See base class."""
        ...
    
    def to_payload(self, value: Any) -> Optional[temporalio.api.common.v1.Payload]:
        """See base class."""
        ...
    
    def from_payload(self, payload: temporalio.api.common.v1.Payload, type_hint: Optional[Type] = ...) -> Any:
        """See base class."""
        ...
    


_JSONTypeConverterUnhandled = NewType("_JSONTypeConverterUnhandled", object)
class JSONTypeConverter(ABC):
    """Converter for converting an object from Python :py:func:`json.loads`
    result (e.g. scalar, list, or dict) to a known type.
    """
    Unhandled = ...
    @abstractmethod
    def to_typed_value(self, hint: Type, value: Any) -> Union[Optional[Any], _JSONTypeConverterUnhandled]:
        """Convert the given value to a type based on the given hint.

        Args:
            hint: Type hint to use to help in converting the value.
            value: Value as returned by :py:func:`json.loads`. Usually a scalar,
                list, or dict.

        Returns:
            The converted value or :py:attr:`Unhandled` if this converter does
            not handle this situation.
        """
        ...
    


class PayloadCodec(ABC):
    """Codec for encoding/decoding to/from bytes.

    Commonly used for compression or encryption.
    """
    @abstractmethod
    async def encode(self, payloads: Sequence[temporalio.api.common.v1.Payload]) -> List[temporalio.api.common.v1.Payload]:
        """Encode the given payloads.

        Args:
            payloads: Payloads to encode. This value should not be mutated.

        Returns:
            Encoded payloads. Note, this does not have to be the same number as
            payloads given, but must be at least one and cannot be more than was
            given.
        """
        ...
    
    @abstractmethod
    async def decode(self, payloads: Sequence[temporalio.api.common.v1.Payload]) -> List[temporalio.api.common.v1.Payload]:
        """Decode the given payloads.

        Args:
            payloads: Payloads to decode. This value should not be mutated.

        Returns:
            Decoded payloads. Note, this does not have to be the same number as
            payloads given, but must be at least one and cannot be more than was
            given.
        """
        ...
    
    async def encode_wrapper(self, payloads: temporalio.api.common.v1.Payloads) -> None:
        """:py:meth:`encode` for the
        :py:class:`temporalio.api.common.v1.Payloads` wrapper.

        This replaces the payloads within the wrapper.
        """
        ...
    
    async def decode_wrapper(self, payloads: temporalio.api.common.v1.Payloads) -> None:
        """:py:meth:`decode` for the
        :py:class:`temporalio.api.common.v1.Payloads` wrapper.

        This replaces the payloads within.
        """
        ...
    
    async def encode_failure(self, failure: temporalio.api.failure.v1.Failure) -> None:
        """Encode payloads of a failure."""
        ...
    
    async def decode_failure(self, failure: temporalio.api.failure.v1.Failure) -> None:
        """Decode payloads of a failure."""
        ...
    


class FailureConverter(ABC):
    """Base failure converter to/from errors.

    Note, for workflow exceptions, :py:attr:`to_failure` is only invoked if the
    exception is an instance of :py:class:`temporalio.exceptions.FailureError`.
    Users should extend :py:class:`temporalio.exceptions.ApplicationError` if
    they want a custom workflow exception to work with this class.
    """
    default: ClassVar[FailureConverter]
    @abstractmethod
    def to_failure(self, exception: BaseException, payload_converter: PayloadConverter, failure: temporalio.api.failure.v1.Failure) -> None:
        """Convert the given exception to a Temporal failure.

        Users should make sure not to alter the ``exception`` input.

        Args:
            exception: The exception to convert.
            payload_converter: The payload converter to use if needed.
            failure: The failure to update with error information.
        """
        ...
    
    @abstractmethod
    def from_failure(self, failure: temporalio.api.failure.v1.Failure, payload_converter: PayloadConverter) -> BaseException:
        """Convert the given Temporal failure to an exception.

        Users should make sure not to alter the ``failure`` input.

        Args:
            failure: The failure to convert.
            payload_converter: The payload converter to use if needed.

        Returns:
            Converted error.
        """
        ...
    


class DefaultFailureConverter(FailureConverter):
    """Default failure converter.

    A singleton instance of this is available at
    :py:attr:`FailureConverter.default`.
    """
    def __init__(self, *, encode_common_attributes: bool = ...) -> None:
        """Create the default failure converter.

        Args:
            encode_common_attributes: If ``True``, the message and stack trace
                of the failure will be moved into the encoded attribute section
                of the failure which can be encoded with a codec.
        """
        ...
    
    def to_failure(self, exception: BaseException, payload_converter: PayloadConverter, failure: temporalio.api.failure.v1.Failure) -> None:
        """See base class."""
        ...
    
    def from_failure(self, failure: temporalio.api.failure.v1.Failure, payload_converter: PayloadConverter) -> BaseException:
        """See base class."""
        ...
    


class DefaultFailureConverterWithEncodedAttributes(DefaultFailureConverter):
    """Implementation of :py:class:`DefaultFailureConverter` which moves message
    and stack trace to encoded attributes subject to a codec.
    """
    def __init__(self) -> None:
        """Create a default failure converter with encoded attributes."""
        ...
    


@dataclass(frozen=True)
class DataConverter:
    """Data converter for converting and encoding payloads to/from Python values.

    This combines :py:class:`PayloadConverter` which converts values with
    :py:class:`PayloadCodec` which encodes bytes.
    """
    payload_converter_class: Type[PayloadConverter] = ...
    payload_codec: Optional[PayloadCodec] = ...
    failure_converter_class: Type[FailureConverter] = ...
    payload_converter: PayloadConverter = ...
    failure_converter: FailureConverter = ...
    default: ClassVar[DataConverter] = ...
    def __post_init__(self) -> None:
        ...
    
    async def encode(self, values: Sequence[Any]) -> List[temporalio.api.common.v1.Payload]:
        """Encode values into payloads.

        First converts values to payloads then encodes payloads using codec.

        Args:
            values: Values to be converted and encoded.

        Returns:
            Converted and encoded payloads. Note, this does not have to be the
            same number as values given, but must be at least one and cannot be
            more than was given.
        """
        ...
    
    async def decode(self, payloads: Sequence[temporalio.api.common.v1.Payload], type_hints: Optional[List[Type]] = ...) -> List[Any]:
        """Decode payloads into values.

        First decodes payloads using codec then converts payloads to values.

        Args:
            payloads: Payloads to be decoded and converted.

        Returns:
            Decoded and converted values.
        """
        ...
    
    async def encode_wrapper(self, values: Sequence[Any]) -> temporalio.api.common.v1.Payloads:
        """:py:meth:`encode` for the
        :py:class:`temporalio.api.common.v1.Payloads` wrapper.
        """
        ...
    
    async def decode_wrapper(self, payloads: Optional[temporalio.api.common.v1.Payloads], type_hints: Optional[List[Type]] = ...) -> List[Any]:
        """:py:meth:`decode` for the
        :py:class:`temporalio.api.common.v1.Payloads` wrapper.
        """
        ...
    
    async def encode_failure(self, exception: BaseException, failure: temporalio.api.failure.v1.Failure) -> None:
        """Convert and encode failure."""
        ...
    
    async def decode_failure(self, failure: temporalio.api.failure.v1.Failure) -> BaseException:
        """Decode and convert failure."""
        ...
    


def default() -> DataConverter:
    """Default data converter.

    .. deprecated::
        Use :py:meth:`DataConverter.default` instead.
    """
    ...

def encode_search_attributes(attributes: Union[temporalio.common.SearchAttributes, temporalio.common.TypedSearchAttributes], api: temporalio.api.common.v1.SearchAttributes) -> None:
    """Convert search attributes into an API message.

    Args:
        attributes: Search attributes to convert. The dictionary form of this is
            DEPRECATED.
        api: API message to set converted attributes on.
    """
    ...

def encode_typed_search_attribute_value(key: temporalio.common.SearchAttributeKey[temporalio.common.SearchAttributeValueType], value: Optional[temporalio.common.SearchAttributeValue]) -> temporalio.api.common.v1.Payload:
    """Convert typed search attribute value into a payload.

    Args:
        key: Key for the value.
        value: Value to convert.

    Returns:
        Payload for the value.
    """
    ...

def encode_search_attribute_values(vals: temporalio.common.SearchAttributeValues) -> temporalio.api.common.v1.Payload:
    """Convert search attribute values into a payload.

    .. deprecated::
        Use typed search attributes instead.

    Args:
        vals: List of values to convert.
    """
    ...

def decode_search_attributes(api: temporalio.api.common.v1.SearchAttributes) -> temporalio.common.SearchAttributes:
    """Decode API search attributes to values.

    .. deprecated::
        Use typed search attributes instead.

    Args:
        api: API message with search attribute values to convert.

    Returns:
        Converted search attribute values (new mapping every time).
    """
    ...

def decode_typed_search_attributes(api: temporalio.api.common.v1.SearchAttributes) -> temporalio.common.TypedSearchAttributes:
    """Decode API search attributes to typed search attributes.

    Args:
        api: API message with search attribute values to convert.

    Returns:
        Typed search attribute collection (new object every time).
    """
    ...

def value_to_type(hint: Type, value: Any, custom_converters: Sequence[JSONTypeConverter] = ...) -> Any:
    """Convert a given value to the given type hint.

    This is used internally to convert a raw JSON loaded value to a specific
    type hint.

    Args:
        hint: Type hint to convert the value to.
        value: Raw value (e.g. primitive, dict, or list) to convert from.
        custom_converters: Set of custom converters to try before doing default
            conversion. Converters are tried in order and the first value that
            is not :py:attr:`JSONTypeConverter.Unhandled` will be returned from
            this function instead of doing default behavior.

    Returns:
        Converted value.

    Raises:
        TypeError: Unable to convert to the given hint.
    """
    ...

