"""Spaces API namespace — domain-specific logic on top of the generated base."""

from __future__ import annotations

from typing import Any

from goodmem._generated.api.spaces_base import AsyncSpacesAPIBase, SpacesAPIBase
from goodmem.pagination import AsyncPaginator, Paginator
from goodmem.registries.convenience import _transform_list_kwargs, apply_convenience_transforms


class SpacesAPI(SpacesAPIBase):
    """Spaces API with GoodMem convenience defaults.

    Extends ``SpacesAPIBase`` with:

    - **Default chunking config**: applies recursive chunking (512 chars, 64 overlap,
      ``KEEP_END`` strategy, ``CHARACTER_COUNT`` measurement) when
      ``default_chunking_config`` is not provided.
    """

    def create(self, **kwargs: Any) -> Any:
        apply_convenience_transforms(("spaces", "create"), kwargs)
        return super().create(**kwargs)

    def list(
        self,
        *,
        labels: dict[str, str] | None = None,
        **kwargs: Any,
    ) -> Paginator:
        max_items = _transform_list_kwargs(kwargs)
        paginator = super().list(labels=labels, **kwargs)
        paginator._max_items = max_items
        return paginator


class AsyncSpacesAPI(AsyncSpacesAPIBase):
    """Async Spaces API with GoodMem convenience defaults. See ``SpacesAPI``."""

    async def create(self, **kwargs: Any) -> Any:
        apply_convenience_transforms(("spaces", "create"), kwargs)
        return await super().create(**kwargs)

    def list(
        self,
        *,
        labels: dict[str, str] | None = None,
        **kwargs: Any,
    ) -> AsyncPaginator:
        max_items = _transform_list_kwargs(kwargs)
        paginator = super().list(labels=labels, **kwargs)
        paginator._max_items = max_items
        return paginator
