# 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/interpolation_mode.fbs".

# You can extend this class by creating a "InterpolationModeExt" class in "interpolation_mode_ext.py".

from __future__ import annotations

from collections.abc import Sequence
from typing import Literal

import pyarrow as pa

from .._baseclasses import (
    BaseBatch,
    ComponentBatchMixin,
)

__all__ = ["InterpolationMode", "InterpolationModeArrayLike", "InterpolationModeBatch", "InterpolationModeLike"]


from enum import Enum


class InterpolationMode(Enum):
    """**Component**: Specifies how values between data points are interpolated in time series."""

    Linear = 1
    """Connect data points with straight line segments."""

    StepAfter = 2
    """
    Hold the previous value until the next data point, then jump.

    The step occurs at the end of the interval.
    """

    StepBefore = 3
    """
    Jump to the new value immediately, then hold until the next data point.

    The step occurs at the beginning of the interval.
    """

    StepMid = 4
    """
    Hold the previous value until the midpoint between data points, then jump to the new value.

    The step occurs at the midpoint of the interval.
    """

    @classmethod
    def auto(cls, val: str | int | InterpolationMode) -> InterpolationMode:
        """Best-effort converter, including a case-insensitive string matcher."""
        if isinstance(val, InterpolationMode):
            return val
        if isinstance(val, int):
            return cls(val)
        try:
            return cls[val]
        except KeyError:
            val_lower = val.lower()
            for variant in cls:
                if variant.name.lower() == val_lower:
                    return variant
        raise ValueError(f"Cannot convert {val} to {cls.__name__}")

    def __str__(self) -> str:
        """Returns the variant name."""
        return self.name


InterpolationModeLike = (
    InterpolationMode
    | Literal["Linear", "StepAfter", "StepBefore", "StepMid", "linear", "stepafter", "stepbefore", "stepmid"]
    | int
)
"""A type alias for any InterpolationMode-like object."""

InterpolationModeArrayLike = (
    InterpolationMode
    | Literal["Linear", "StepAfter", "StepBefore", "StepMid", "linear", "stepafter", "stepbefore", "stepmid"]
    | int
    | Sequence[InterpolationModeLike]
)
"""A type alias for any InterpolationMode-like array object."""


class InterpolationModeBatch(BaseBatch[InterpolationModeArrayLike], ComponentBatchMixin):
    _ARROW_DATATYPE = pa.uint8()
    _COMPONENT_TYPE: str = "rerun.components.InterpolationMode"

    @staticmethod
    def _native_to_pa_array(data: InterpolationModeArrayLike, data_type: pa.DataType) -> pa.Array:
        if isinstance(data, (InterpolationMode, int, str)):
            data = [data]

        pa_data = [InterpolationMode.auto(v).value if v is not None else None for v in data]  # type: ignore[redundant-expr]  # ty: ignore[not-iterable]

        return pa.array(pa_data, type=data_type)
