"""
Generated from ``clients/src/main/resources/common/message/ConsumerGroupHeartbeatRequest.json``.
"""

import datetime
import uuid

from dataclasses import dataclass
from dataclasses import field
from typing import ClassVar

from kio.schema.request_header.v2.header import RequestHeader
from kio.schema.types import GroupId
from kio.schema.types import TopicName
from kio.static.constants import EntityType
from kio.static.primitive import i16
from kio.static.primitive import i32
from kio.static.primitive import i32Timedelta


@dataclass(frozen=True, slots=True, kw_only=True)
class TopicPartitions:
    __type__: ClassVar = EntityType.nested
    __version__: ClassVar[i16] = i16(0)
    __flexible__: ClassVar[bool] = True
    __api_key__: ClassVar[i16] = i16(68)
    __header_schema__: ClassVar[type[RequestHeader]] = RequestHeader
    topic_id: uuid.UUID | None = field(metadata={"kafka_type": "uuid"})
    """The topic ID."""
    partitions: tuple[i32, ...] = field(metadata={"kafka_type": "int32"}, default=())
    """The partitions."""


@dataclass(frozen=True, slots=True, kw_only=True)
class ConsumerGroupHeartbeatRequest:
    __type__: ClassVar = EntityType.request
    __version__: ClassVar[i16] = i16(0)
    __flexible__: ClassVar[bool] = True
    __api_key__: ClassVar[i16] = i16(68)
    __header_schema__: ClassVar[type[RequestHeader]] = RequestHeader
    group_id: GroupId = field(metadata={"kafka_type": "string"})
    """The group identifier."""
    member_id: str = field(metadata={"kafka_type": "string"})
    """The member id generated by the coordinator. The member id must be kept during the entire lifetime of the member."""
    member_epoch: i32 = field(metadata={"kafka_type": "int32"})
    """The current member epoch; 0 to join the group; -1 to leave the group; -2 to indicate that the static member will rejoin."""
    instance_id: str | None = field(metadata={"kafka_type": "string"}, default=None)
    """null if not provided or if it didn't change since the last heartbeat; the instance Id otherwise."""
    rack_id: str | None = field(metadata={"kafka_type": "string"}, default=None)
    """null if not provided or if it didn't change since the last heartbeat; the rack ID of consumer otherwise."""
    rebalance_timeout: i32Timedelta = field(
        metadata={"kafka_type": "timedelta_i32"},
        default=i32Timedelta.parse(datetime.timedelta(milliseconds=-1)),
    )
    """-1 if it didn't change since the last heartbeat; the maximum time in milliseconds that the coordinator will wait on the member to revoke its partitions otherwise."""
    subscribed_topic_names: tuple[TopicName, ...] = field(
        metadata={"kafka_type": "string"}, default=()
    )
    """null if it didn't change since the last heartbeat; the subscribed topic names otherwise."""
    server_assignor: str | None = field(metadata={"kafka_type": "string"}, default=None)
    """null if not used or if it didn't change since the last heartbeat; the server side assignor to use otherwise."""
    topic_partitions: tuple[TopicPartitions, ...] | None
    """null if it didn't change since the last heartbeat; the partitions owned by the member."""
