import abc
from _typeshed import Incomplete
from enum import IntEnum

log: Incomplete
NO_PRODUCER_ID: int
NO_PRODUCER_EPOCH: int
NO_SEQUENCE: int

class ProducerIdAndEpoch:
    producer_id: Incomplete
    epoch: Incomplete
    def __init__(self, producer_id, epoch) -> None: ...
    @property
    def is_valid(self): ...
    def match(self, batch): ...
    def __eq__(self, other): ...

class TransactionState(IntEnum):
    UNINITIALIZED = 0
    INITIALIZING = 1
    READY = 2
    IN_TRANSACTION = 3
    COMMITTING_TRANSACTION = 4
    ABORTING_TRANSACTION = 5
    ABORTABLE_ERROR = 6
    FATAL_ERROR = 7
    @classmethod
    def is_transition_valid(cls, source, target): ...

class Priority(IntEnum):
    FIND_COORDINATOR = 0
    INIT_PRODUCER_ID = 1
    ADD_PARTITIONS_OR_OFFSETS = 2
    END_TXN = 3

class TransactionManager:
    NO_INFLIGHT_REQUEST_CORRELATION_ID: int
    ADD_PARTITIONS_RETRY_BACKOFF_MS: int
    transactional_id: Incomplete
    transaction_timeout_ms: Incomplete
    producer_id_and_epoch: Incomplete
    retry_backoff_ms: Incomplete
    def __init__(
        self,
        transactional_id=None,
        transaction_timeout_ms: int = 0,
        retry_backoff_ms: int = 100,
        api_version=(0, 11),
        metadata=None,
    ) -> None: ...
    def initialize_transactions(self): ...
    def begin_transaction(self) -> None: ...
    def begin_commit(self): ...
    def begin_abort(self): ...
    def send_offsets_to_transaction(self, offsets, consumer_group_id): ...
    def maybe_add_partition_to_transaction(self, topic_partition) -> None: ...
    def is_send_to_partition_allowed(self, tp): ...
    def has_producer_id(self, producer_id=None): ...
    def is_transactional(self): ...
    def has_partitions_to_add(self): ...
    def is_completing(self): ...
    @property
    def last_error(self): ...
    def has_error(self): ...
    def is_aborting(self): ...
    def transition_to_abortable_error(self, exc) -> None: ...
    def transition_to_fatal_error(self, exc) -> None: ...
    def is_partition_added(self, partition): ...
    def is_partition_pending_add(self, partition): ...
    def has_producer_id_and_epoch(self, producer_id, producer_epoch): ...
    def set_producer_id_and_epoch(self, producer_id_and_epoch) -> None: ...
    def reset_producer_id(self) -> None: ...
    def sequence_number(self, tp): ...
    def increment_sequence_number(self, tp, increment) -> None: ...
    def reset_sequence_for_partition(self, tp) -> None: ...
    def next_request_handler(self, has_incomplete_batches): ...
    def retry(self, request) -> None: ...
    def authentication_failed(self, exc) -> None: ...
    def coordinator(self, coord_type): ...
    def lookup_coordinator_for_request(self, request) -> None: ...
    def next_in_flight_request_correlation_id(self): ...
    def clear_in_flight_transactional_request_correlation_id(self) -> None: ...
    def has_in_flight_transactional_request(self): ...
    def has_fatal_error(self): ...
    def has_abortable_error(self): ...

class TransactionalRequestResult:
    def __init__(self) -> None: ...
    def done(self, error=None) -> None: ...
    def wait(self, timeout_ms=None): ...
    @property
    def is_done(self): ...
    @property
    def succeeded(self): ...
    @property
    def failed(self): ...
    @property
    def exception(self): ...

class TxnRequestHandler(metaclass=abc.ABCMeta):
    transaction_manager: Incomplete
    retry_backoff_ms: Incomplete
    request: Incomplete
    def __init__(self, transaction_manager, result=None) -> None: ...
    @property
    def transactional_id(self): ...
    @property
    def producer_id(self): ...
    @property
    def producer_epoch(self): ...
    def fatal_error(self, exc) -> None: ...
    def abortable_error(self, exc) -> None: ...
    def fail(self, exc) -> None: ...
    def reenqueue(self) -> None: ...
    def on_complete(self, correlation_id, response_or_exc) -> None: ...
    def needs_coordinator(self): ...
    @property
    def result(self): ...
    @property
    def coordinator_type(self): ...
    @property
    def coordinator_key(self): ...
    def set_retry(self) -> None: ...
    @property
    def is_retry(self): ...
    @abc.abstractmethod
    def handle_response(self, response): ...
    @property
    @abc.abstractmethod
    def priority(self): ...

class InitProducerIdHandler(TxnRequestHandler):
    request: Incomplete
    def __init__(self, transaction_manager, transaction_timeout_ms) -> None: ...
    @property
    def priority(self): ...
    def handle_response(self, response) -> None: ...

class AddPartitionsToTxnHandler(TxnRequestHandler):
    request: Incomplete
    def __init__(self, transaction_manager, topic_partitions) -> None: ...
    @property
    def priority(self): ...
    retry_backoff_ms: Incomplete
    def handle_response(self, response) -> None: ...
    def maybe_override_retry_backoff_ms(self) -> None: ...

class FindCoordinatorHandler(TxnRequestHandler):
    request: Incomplete
    def __init__(self, transaction_manager, coord_type, coord_key) -> None: ...
    @property
    def priority(self): ...
    @property
    def coordinator_type(self) -> None: ...
    @property
    def coordinator_key(self) -> None: ...
    def handle_response(self, response) -> None: ...

class EndTxnHandler(TxnRequestHandler):
    request: Incomplete
    def __init__(self, transaction_manager, committed) -> None: ...
    @property
    def priority(self): ...
    def handle_response(self, response) -> None: ...

class AddOffsetsToTxnHandler(TxnRequestHandler):
    consumer_group_id: Incomplete
    offsets: Incomplete
    request: Incomplete
    def __init__(self, transaction_manager, consumer_group_id, offsets) -> None: ...
    @property
    def priority(self): ...
    def handle_response(self, response) -> None: ...

class TxnOffsetCommitHandler(TxnRequestHandler):
    consumer_group_id: Incomplete
    offsets: Incomplete
    request: Incomplete
    def __init__(self, transaction_manager, consumer_group_id, offsets, result) -> None: ...
    @property
    def priority(self): ...
    @property
    def coordinator_type(self): ...
    @property
    def coordinator_key(self): ...
    def handle_response(self, response) -> None: ...
