# DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/python/mod.rs
# Based on "crates/store/re_sdk_types/definitions/rerun/components/key_value_pairs.fbs".

# You can extend this class by creating a "KeyValuePairsExt" class in "key_value_pairs_ext.py".

from __future__ import annotations

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

import pyarrow as pa
from attrs import define, field

from .._baseclasses import (
    BaseBatch,
    ComponentBatchMixin,
    ComponentMixin,
)
from .key_value_pairs_ext import KeyValuePairsExt

if TYPE_CHECKING:
    from .. import datatypes

__all__ = ["KeyValuePairs", "KeyValuePairsArrayLike", "KeyValuePairsBatch", "KeyValuePairsLike"]


@define(init=False)
class KeyValuePairs(KeyValuePairsExt, ComponentMixin):
    """
    **Component**: A map of string keys to string values.

    This component can be used to attach arbitrary metadata or annotations to entities.
    Each key-value pair is stored as a UTF-8 string mapping.

    ⚠️ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
    """

    _BATCH_TYPE = None

    def __init__(self: Any, pairs: KeyValuePairsLike) -> None:
        """
        Create a new instance of the KeyValuePairs component.

        Parameters
        ----------
        pairs:
            The key-value pairs that make up this string map.

        """

        # You can define your own __init__ function as a member of KeyValuePairsExt in key_value_pairs_ext.py
        self.__attrs_init__(pairs=pairs)

    pairs: list[datatypes.Utf8Pair] = field(
        converter=KeyValuePairsExt.pairs__field_converter_override,  # type: ignore[misc]
    )
    # The key-value pairs that make up this string map.
    #
    # (Docstring intentionally commented out to hide this field from the docs)

    def __len__(self) -> int:
        # You can define your own __len__ function as a member of KeyValuePairsExt in key_value_pairs_ext.py
        return len(self.pairs)


if TYPE_CHECKING:
    KeyValuePairsLike = KeyValuePairs | dict[str, str]
    """A type alias for any KeyValuePairs-like object."""
else:
    KeyValuePairsLike = Any

KeyValuePairsArrayLike = KeyValuePairs | Sequence[KeyValuePairsLike] | dict[str, str] | Sequence[dict[str, str]]
"""A type alias for any KeyValuePairs-like array object."""


class KeyValuePairsBatch(BaseBatch[KeyValuePairsArrayLike], ComponentBatchMixin):
    _ARROW_DATATYPE = pa.list_(
        pa.field(
            "item",
            pa.struct([
                pa.field("first", pa.utf8(), nullable=False, metadata={}),
                pa.field("second", pa.utf8(), nullable=False, metadata={}),
            ]),
            nullable=False,
            metadata={},
        )
    )
    _COMPONENT_TYPE: str = "rerun.components.KeyValuePairs"

    @staticmethod
    def _native_to_pa_array(data: KeyValuePairsArrayLike, data_type: pa.DataType) -> pa.Array:
        return KeyValuePairsExt.native_to_pa_array_override(data, data_type)


# This is patched in late to avoid circular dependencies.
KeyValuePairs._BATCH_TYPE = KeyValuePairsBatch  # type: ignore[assignment]
