""" Other useful structs """
from __future__ import absolute_import

from collections import namedtuple


"""A topic and partition tuple

Keyword Arguments:
    topic (str): A topic name
    partition (int): A partition id
"""
TopicPartition = namedtuple("TopicPartition",
    ["topic", "partition"])


"""A Kafka broker metadata used by admin tools.

Keyword Arguments:
    nodeID (int): The Kafka broker id.
    host (str): The Kafka broker hostname.
    port (int): The Kafka broker port.
    rack (str): The rack of the broker, which is used to in rack aware
                partition assignment for fault tolerance.
    Examples: `RACK1`, `us-east-1d`. Default: None
"""
BrokerMetadata = namedtuple("BrokerMetadata",
    ["nodeId", "host", "port", "rack"])


"""A topic partition metadata describing the state in the MetadataResponse.

Keyword Arguments:
    topic (str): The topic name of the partition this metadata relates to.
    partition (int): The id of the partition this metadata relates to.
    leader (int): The id of the broker that is the leader for the partition.
    replicas (List[int]): The ids of all brokers that contain replicas of the
                          partition.
    isr (List[int]): The ids of all brokers that contain in-sync replicas of
                     the partition.
    error (KafkaError): A KafkaError object associated with the request for
                        this partition metadata.
"""
PartitionMetadata = namedtuple("PartitionMetadata",
    ["topic", "partition", "leader", "replicas", "isr", "error"])


"""The Kafka offset commit API

The Kafka offset commit API allows users to provide additional metadata
(in the form of a string) when an offset is committed. This can be useful
(for example) to store information about which node made the commit,
what time the commit was made, etc.

Keyword Arguments:
    offset (int): The offset to be committed
    metadata (str): Non-null metadata
"""
OffsetAndMetadata = namedtuple("OffsetAndMetadata",
    # TODO add leaderEpoch: OffsetAndMetadata(offset, leaderEpoch, metadata)
    ["offset", "metadata"])


"""An offset and timestamp tuple

Keyword Arguments:
    offset (int): An offset
    timestamp (int): The timestamp associated to the offset
"""
OffsetAndTimestamp = namedtuple("OffsetAndTimestamp",
    ["offset", "timestamp"])

MemberInformation = namedtuple("MemberInformation",
    ["member_id", "client_id", "client_host", "member_metadata", "member_assignment"])

GroupInformation = namedtuple("GroupInformation",
    ["error_code", "group", "state", "protocol_type", "protocol", "members", "authorized_operations"])

"""Define retry policy for async producer

Keyword Arguments:
    Limit (int): Number of retries. limit >= 0, 0 means no retries
    backoff_ms (int): Milliseconds to backoff.
    retry_on_timeouts:
"""
RetryOptions = namedtuple("RetryOptions",
    ["limit", "backoff_ms", "retry_on_timeouts"])

[((13, 17, 14, 27), 'collections.namedtuple', 'namedtuple', ({(13, 28, 13, 44): '"""TopicPartition"""', (14, 4, 14, 26): "['topic', 'partition']"}, {}), "('TopicPartition', ['topic', 'partition'])", False, 'from collections import namedtuple\n'), ((27, 17, 28, 39), 'collections.namedtuple', 'namedtuple', ({(27, 28, 27, 44): '"""BrokerMetadata"""', (28, 4, 28, 38): "['nodeId', 'host', 'port', 'rack']"}, {}), "('BrokerMetadata', ['nodeId', 'host', 'port', 'rack'])", False, 'from collections import namedtuple\n'), ((44, 20, 45, 65), 'collections.namedtuple', 'namedtuple', ({(44, 31, 44, 50): '"""PartitionMetadata"""', (45, 4, 45, 64): "['topic', 'partition', 'leader', 'replicas', 'isr', 'error']"}, {}), "('PartitionMetadata', ['topic', 'partition', 'leader', 'replicas',\n    'isr', 'error'])", False, 'from collections import namedtuple\n'), ((59, 20, 61, 27), 'collections.namedtuple', 'namedtuple', ({(59, 31, 59, 50): '"""OffsetAndMetadata"""', (61, 4, 61, 26): "['offset', 'metadata']"}, {}), "('OffsetAndMetadata', ['offset', 'metadata'])", False, 'from collections import namedtuple\n'), ((70, 21, 71, 28), 'collections.namedtuple', 'namedtuple', ({(70, 32, 70, 52): '"""OffsetAndTimestamp"""', (71, 4, 71, 27): "['offset', 'timestamp']"}, {}), "('OffsetAndTimestamp', ['offset', 'timestamp'])", False, 'from collections import namedtuple\n'), ((73, 20, 74, 86), 'collections.namedtuple', 'namedtuple', ({(73, 31, 73, 50): '"""MemberInformation"""', (74, 4, 74, 85): "['member_id', 'client_id', 'client_host', 'member_metadata',\n    'member_assignment']"}, {}), "('MemberInformation', ['member_id', 'client_id', 'client_host',\n    'member_metadata', 'member_assignment'])", False, 'from collections import namedtuple\n'), ((76, 19, 77, 102), 'collections.namedtuple', 'namedtuple', ({(76, 30, 76, 48): '"""GroupInformation"""', (77, 4, 77, 101): "['error_code', 'group', 'state', 'protocol_type', 'protocol', 'members',\n    'authorized_operations']"}, {}), "('GroupInformation', ['error_code', 'group', 'state',\n    'protocol_type', 'protocol', 'members', 'authorized_operations'])", False, 'from collections import namedtuple\n'), ((86, 15, 87, 49), 'collections.namedtuple', 'namedtuple', ({(86, 26, 86, 40): '"""RetryOptions"""', (87, 4, 87, 48): "['limit', 'backoff_ms', 'retry_on_timeouts']"}, {}), "('RetryOptions', ['limit', 'backoff_ms', 'retry_on_timeouts'])", False, 'from collections import namedtuple\n')]