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

import temporalio.api.common.v1
import temporalio.types
from abc import ABC, abstractmethod
from collections.abc import Collection, Iterator, Mapping, Sequence
from dataclasses import dataclass
from datetime import datetime, timedelta
from enum import IntEnum
from typing import Any, ClassVar, Generic, NamedTuple, TypeVar, overload

"""
This type stub file was generated by pyright.
"""
@dataclass
class RetryPolicy:
    """Options for retrying workflows and activities."""
    initial_interval: timedelta = ...
    backoff_coefficient: float = ...
    maximum_interval: timedelta | None = ...
    maximum_attempts: int = ...
    non_retryable_error_types: Sequence[str] | None = ...
    @staticmethod
    def from_proto(proto: temporalio.api.common.v1.RetryPolicy) -> RetryPolicy:
        """Create a retry policy from the proto object."""
        ...
    
    def apply_to_proto(self, proto: temporalio.api.common.v1.RetryPolicy) -> None:
        """Apply the fields in this policy to the given proto object."""
        ...
    


class WorkflowIDReusePolicy(IntEnum):
    """How already-in-use workflow IDs are handled on start.

    See :py:class:`temporalio.api.enums.v1.WorkflowIdReusePolicy`.
    """
    ALLOW_DUPLICATE = ...
    ALLOW_DUPLICATE_FAILED_ONLY = ...
    REJECT_DUPLICATE = ...
    TERMINATE_IF_RUNNING = ...


class WorkflowIDConflictPolicy(IntEnum):
    """How already-running workflows of the same ID are handled on start.

    See :py:class:`temporalio.api.enums.v1.WorkflowIdConflictPolicy`.
    """
    UNSPECIFIED = ...
    FAIL = ...
    USE_EXISTING = ...
    TERMINATE_EXISTING = ...


class QueryRejectCondition(IntEnum):
    """Whether a query should be rejected in certain conditions.

    See :py:class:`temporalio.api.enums.v1.QueryRejectCondition`.
    """
    NONE = ...
    NOT_OPEN = ...
    NOT_COMPLETED_CLEANLY = ...


class HeaderCodecBehavior(IntEnum):
    """Different ways to handle header encoding"""
    NO_CODEC = ...
    CODEC = ...
    WORKFLOW_ONLY_CODEC = ...


@dataclass(frozen=True)
class RawValue:
    """Representation of an unconverted, raw payload.

    This type can be used as a parameter or return type in workflows,
    activities, signals, and queries to pass through a raw payload.
    Encoding/decoding of the payload is still done by the system.
    """
    payload: temporalio.api.common.v1.Payload
    def __getstate__(self) -> object:
        """Pickle support."""
        ...
    
    def __setstate__(self, state: object) -> None:
        """Pickle support."""
        ...
    


SearchAttributeValues = list[str] | list[int] | list[float] | list[bool] | list[datetime]
SearchAttributes = Mapping[str, SearchAttributeValues]
SearchAttributeValue = str | int | float | bool | datetime | Sequence[str]
SearchAttributeValueType = TypeVar("SearchAttributeValueType", str, int, float, bool, datetime, Sequence[str])
class SearchAttributeIndexedValueType(IntEnum):
    """Server index type of a search attribute."""
    TEXT = ...
    KEYWORD = ...
    INT = ...
    DOUBLE = ...
    BOOL = ...
    DATETIME = ...
    KEYWORD_LIST = ...


class SearchAttributeKey(ABC, Generic[SearchAttributeValueType]):
    """Typed search attribute key representation.

    Use one of the ``for`` static methods here to create a key.
    """
    @property
    @abstractmethod
    def name(self) -> str:
        """Get the name of the key."""
        ...
    
    @property
    @abstractmethod
    def indexed_value_type(self) -> SearchAttributeIndexedValueType:
        """Get the server index typed of the key"""
        ...
    
    @property
    @abstractmethod
    def value_type(self) -> type[SearchAttributeValueType]:
        """Get the Python type of value for the key.

        This may contain generics which cannot be used in ``isinstance``.
        :py:attr:`origin_value_type` can be used instead.
        """
        ...
    
    @property
    def origin_value_type(self) -> type:
        """Get the Python type of value for the key without generics."""
        ...
    
    def value_set(self, value: SearchAttributeValueType) -> SearchAttributeUpdate[SearchAttributeValueType]:
        """Create a search attribute update to set the given value on this
        key.
        """
        ...
    
    def value_unset(self) -> SearchAttributeUpdate[SearchAttributeValueType]:
        """Create a search attribute update to unset the value on this key."""
        ...
    
    @staticmethod
    def for_text(name: str) -> SearchAttributeKey[str]:
        """Create a 'Text' search attribute type."""
        ...
    
    @staticmethod
    def for_keyword(name: str) -> SearchAttributeKey[str]:
        """Create a 'Keyword' search attribute type."""
        ...
    
    @staticmethod
    def for_int(name: str) -> SearchAttributeKey[int]:
        """Create an 'Int' search attribute type."""
        ...
    
    @staticmethod
    def for_float(name: str) -> SearchAttributeKey[float]:
        """Create a 'Double' search attribute type."""
        ...
    
    @staticmethod
    def for_bool(name: str) -> SearchAttributeKey[bool]:
        """Create a 'Bool' search attribute type."""
        ...
    
    @staticmethod
    def for_datetime(name: str) -> SearchAttributeKey[datetime]:
        """Create a 'Datetime' search attribute type."""
        ...
    
    @staticmethod
    def for_keyword_list(name: str) -> SearchAttributeKey[Sequence[str]]:
        """Create a 'KeywordList' search attribute type."""
        ...
    


@dataclass(frozen=True)
class _SearchAttributeKey(SearchAttributeKey[SearchAttributeValueType]):
    _name: str
    _indexed_value_type: SearchAttributeIndexedValueType
    _value_type: type[SearchAttributeValueType]
    @property
    def name(self) -> str:
        ...
    
    @property
    def indexed_value_type(self) -> SearchAttributeIndexedValueType:
        ...
    
    @property
    def value_type(self) -> type[SearchAttributeValueType]:
        ...
    


class SearchAttributePair(NamedTuple, Generic[SearchAttributeValueType]):
    """A named tuple representing a key/value search attribute pair."""
    key: SearchAttributeKey[SearchAttributeValueType]
    value: SearchAttributeValueType
    ...


class SearchAttributeUpdate(ABC, Generic[SearchAttributeValueType]):
    """Representation of a search attribute update."""
    @property
    @abstractmethod
    def key(self) -> SearchAttributeKey[SearchAttributeValueType]:
        """Key that is being set."""
        ...
    
    @property
    @abstractmethod
    def value(self) -> SearchAttributeValueType | None:
        """Value that is being set or ``None`` if being unset."""
        ...
    


@dataclass(frozen=True)
class _SearchAttributeUpdate(SearchAttributeUpdate[SearchAttributeValueType]):
    _key: SearchAttributeKey[SearchAttributeValueType]
    _value: SearchAttributeValueType | None
    @property
    def key(self) -> SearchAttributeKey[SearchAttributeValueType]:
        ...
    
    @property
    def value(self) -> SearchAttributeValueType | None:
        ...
    


@dataclass(frozen=True)
class TypedSearchAttributes(Collection[SearchAttributePair]):
    """Collection of typed search attributes.

    This is represented as an immutable collection of
    :py:class:`SearchAttributePair`. This can be created passing a sequence of
    pairs to the constructor.
    """
    search_attributes: Sequence[SearchAttributePair]
    empty: ClassVar[TypedSearchAttributes]
    def __post_init__(self):
        """Post-init initialization."""
        ...
    
    def __len__(self) -> int:
        """Get the number of search attributes."""
        ...
    
    def __getitem__(self, key: SearchAttributeKey[SearchAttributeValueType]) -> SearchAttributeValueType:
        """Get a single search attribute value by key or fail with
        ``KeyError``.
        """
        ...
    
    def __iter__(self) -> Iterator[SearchAttributePair]:
        """Get an iterator over search attribute key/value pairs."""
        ...
    
    def __contains__(self, key: object) -> bool:
        """Check whether this search attribute contains the given key.

        This uses key equality so the key must be the same name and type.
        """
        ...
    
    @overload
    def get(self, key: SearchAttributeKey[SearchAttributeValueType]) -> SearchAttributeValueType | None:
        ...
    
    @overload
    def get(self, key: SearchAttributeKey[SearchAttributeValueType], default: temporalio.types.AnyType) -> SearchAttributeValueType | temporalio.types.AnyType:
        ...
    
    def get(self, key: SearchAttributeKey[SearchAttributeValueType], default: Any | None = ...) -> Any:
        """Get an attribute value for a key (or default). This is similar to
        dict.get.
        """
        ...
    
    def updated(self, *search_attributes: SearchAttributePair) -> TypedSearchAttributes:
        """Copy this collection, replacing attributes with matching key names or
        adding if key name not present.
        """
        ...
    


MetricAttributes = ...
class MetricMeter(ABC):
    """Metric meter for recording metrics."""
    noop: ClassVar[MetricMeter]
    @abstractmethod
    def create_counter(self, name: str, description: str | None = ..., unit: str | None = ...) -> MetricCounter:
        """Create a counter metric for adding values.

        Args:
            name: Name for the metric.
            description: Optional description for the metric.
            unit: Optional unit for the metric.

        Returns:
            Counter metric.
        """
        ...
    
    @abstractmethod
    def create_histogram(self, name: str, description: str | None = ..., unit: str | None = ...) -> MetricHistogram:
        """Create a histogram metric for recording values.

        Args:
            name: Name for the metric.
            description: Optional description for the metric.
            unit: Optional unit for the metric.

        Returns:
            Histogram metric.
        """
        ...
    
    @abstractmethod
    def create_gauge(self, name: str, description: str | None = ..., unit: str | None = ...) -> MetricGauge:
        """Create a gauge metric for setting values.

        Args:
            name: Name for the metric.
            description: Optional description for the metric.
            unit: Optional unit for the metric.

        Returns:
            Gauge metric.
        """
        ...
    
    @abstractmethod
    def with_additional_attributes(self, additional_attributes: MetricAttributes) -> MetricMeter:
        """Create a new metric meter with the given attributes appended to the
        current set.

        Args:
            additional_attributes: Additional attributes to append to the
                current set.

        Returns:
            New metric meter.

        Raises:
            TypeError: Attribute values are not the expected type.
        """
        ...
    


class MetricCounter(ABC):
    """Counter metric created by a metric meter."""
    @property
    @abstractmethod
    def name(self) -> str:
        """Name for the metric."""
        ...
    
    @property
    @abstractmethod
    def description(self) -> str | None:
        """Description for the metric if any."""
        ...
    
    @property
    @abstractmethod
    def unit(self) -> str | None:
        """Unit for the metric if any."""
        ...
    
    @abstractmethod
    def add(self, value: int, additional_attributes: MetricAttributes | None = ...) -> None:
        """Add a value to the counter.

        Args:
            value: A non-negative integer to add.
            additional_attributes: Additional attributes to append to the
                current set.

        Raises:
            ValueError: Value is negative.
            TypeError: Attribute values are not the expected type.
        """
        ...
    
    @abstractmethod
    def with_additional_attributes(self, additional_attributes: MetricAttributes) -> MetricCounter:
        """Create a new counter with the given attributes appended to the
        current set.

        Args:
            additional_attributes: Additional attributes to append to the
                current set.

        Returns:
            New counter.

        Raises:
            TypeError: Attribute values are not the expected type.
        """
        ...
    


class MetricHistogram(ABC):
    """Histogram metric created by a metric meter."""
    @property
    @abstractmethod
    def name(self) -> str:
        """Name for the metric."""
        ...
    
    @property
    @abstractmethod
    def description(self) -> str | None:
        """Description for the metric if any."""
        ...
    
    @property
    @abstractmethod
    def unit(self) -> str | None:
        """Unit for the metric if any."""
        ...
    
    @abstractmethod
    def record(self, value: int, additional_attributes: MetricAttributes | None = ...) -> None:
        """Record a value on the histogram.

        Args:
            value: A non-negative integer to record.
            additional_attributes: Additional attributes to append to the
                current set.

        Raises:
            ValueError: Value is negative.
            TypeError: Attribute values are not the expected type.
        """
        ...
    
    @abstractmethod
    def with_additional_attributes(self, additional_attributes: MetricAttributes) -> MetricHistogram:
        """Create a new histogram with the given attributes appended to the
        current set.

        Args:
            additional_attributes: Additional attributes to append to the
                current set.

        Returns:
            New histogram.

        Raises:
            TypeError: Attribute values are not the expected type.
        """
        ...
    


class MetricGauge(ABC):
    """Gauge metric created by a metric meter."""
    @property
    @abstractmethod
    def name(self) -> str:
        """Name for the metric."""
        ...
    
    @property
    @abstractmethod
    def description(self) -> str | None:
        """Description for the metric if any."""
        ...
    
    @property
    @abstractmethod
    def unit(self) -> str | None:
        """Unit for the metric if any."""
        ...
    
    @abstractmethod
    def set(self, value: int, additional_attributes: MetricAttributes | None = ...) -> None:
        """Set a value on the gauge.

        Args:
            value: A non-negative integer to set.
            additional_attributes: Additional attributes to append to the
                current set.

        Raises:
            ValueError: Value is negative.
            TypeError: Attribute values are not the expected type.
        """
        ...
    
    @abstractmethod
    def with_additional_attributes(self, additional_attributes: MetricAttributes) -> MetricGauge:
        """Create a new gauge with the given attributes appended to the
        current set.

        Args:
            additional_attributes: Additional attributes to append to the
                current set.

        Returns:
            New gauge.

        Raises:
            TypeError: Attribute values are not the expected type.
        """
        ...
    


class _NoopMetricMeter(MetricMeter):
    def create_counter(self, name: str, description: str | None = ..., unit: str | None = ...) -> MetricCounter:
        ...
    
    def create_histogram(self, name: str, description: str | None = ..., unit: str | None = ...) -> MetricHistogram:
        ...
    
    def create_gauge(self, name: str, description: str | None = ..., unit: str | None = ...) -> MetricGauge:
        ...
    
    def with_additional_attributes(self, additional_attributes: MetricAttributes) -> MetricMeter:
        ...
    


class _NoopMetric:
    def __init__(self, name: str, description: str | None, unit: str | None) -> None:
        ...
    
    @property
    def name(self) -> str:
        ...
    
    @property
    def description(self) -> str | None:
        ...
    
    @property
    def unit(self) -> str | None:
        ...
    


class _NoopMetricCounter(_NoopMetric, MetricCounter):
    def add(self, value: int, additional_attributes: MetricAttributes | None = ...) -> None:
        ...
    
    def with_additional_attributes(self, additional_attributes: MetricAttributes) -> MetricCounter:
        ...
    


class _NoopMetricHistogram(_NoopMetric, MetricHistogram):
    def record(self, value: int, additional_attributes: MetricAttributes | None = ...) -> None:
        ...
    
    def with_additional_attributes(self, additional_attributes: MetricAttributes) -> MetricHistogram:
        ...
    


class _NoopMetricGauge(_NoopMetric, MetricGauge):
    def set(self, value: int, additional_attributes: MetricAttributes | None = ...) -> None:
        ...
    
    def with_additional_attributes(self, additional_attributes: MetricAttributes) -> MetricGauge:
        ...
    


_arg_unset = ...
_non_user_defined_callables = ...
