from collections.abc import Callable, Sequence
from typing import Any

from kombu.connection import Connection
from kombu.message import Message
from kombu.messaging import Consumer as MessagingConsumer
from kombu.messaging import Producer
from kombu.transport.base import StdChannel
from kombu.utils.limits import TokenBucket
from typing_extensions import override

__all__ = ("ConsumerMixin", "ConsumerProducerMixin")

class ConsumerMixin:
    connect_max_retries: int | None
    should_stop: bool
    def get_consumers(
        self, Consumer: Callable[..., MessagingConsumer], channel: StdChannel
    ) -> Sequence[MessagingConsumer]: ...
    def on_connection_revived(self) -> None: ...
    def on_consume_ready(
        self,
        connection: Connection,
        channel: StdChannel,
        consumers: Sequence[MessagingConsumer],
        **kwargs: Any,
    ) -> None: ...
    def on_consume_end(self, connection: Connection, channel: StdChannel) -> None: ...
    def on_iteration(self) -> None: ...
    def on_decode_error(self, message: Message, exc: Exception) -> None: ...
    def on_connection_error(self, exc: Exception, interval: int) -> None: ...
    def extra_context(self, connection: Connection, channel: StdChannel) -> None: ...
    def run(self, _tokens: int = ..., **kwargs: Any) -> None: ...
    def consumer_context(
        self, **kwargs: Any
    ) -> tuple[Connection, StdChannel, Sequence[MessagingConsumer]]: ...
    def consume(
        self,
        limit: int | None = ...,
        timeout: int | None = ...,
        safety_interval: int = ...,
        **kwargs: Any,
    ) -> None: ...
    def maybe_conn_error(self, fun: Callable[..., Any] | None) -> Any: ...
    def create_connection(self) -> Connection: ...
    def establish_connection(self) -> Connection: ...
    def _consume_from(self, *queues: Any) -> Sequence[MessagingConsumer]: ...
    def Consumer(
        self,
    ) -> tuple[Connection, StdChannel, Sequence[MessagingConsumer]]: ...
    @property
    def restart_limit(self) -> TokenBucket: ...
    @property
    def connection_errors(self) -> Sequence[Exception]: ...
    @property
    def channel_errors(self) -> Sequence[Exception]: ...

class ConsumerProducerMixin(ConsumerMixin):
    @override
    def on_consume_end(self, connection: Connection, channel: StdChannel) -> None: ...
    @property
    def producer(self) -> Producer: ...
    @property
    def producer_connection(self) -> Connection: ...
