# DO NOT EDIT — generated by _client_gen/convenience_emitter.py from convenience.json.
# Regenerate with: cd clients/v2 && python -c "from _client_gen.convenience_emitter import generate_convenience; generate_convenience()"

"""Spaces API namespace — generated from convenience.json."""

from __future__ import annotations

from typing import Any

from goodmem._api_base.spaces import SpacesAPIBase, AsyncSpacesAPIBase


# --- Convenience imports ---
from goodmem._transforms import apply_convenience_transforms
from goodmem._transforms import _transform_list_kwargs
from goodmem.models.chunking_configuration import ChunkingConfiguration
from goodmem.models.sort_order import SortOrder
from goodmem.models.space import Space
from goodmem.models.space_embedder_config import SpaceEmbedderConfig
from goodmem.pagination import AsyncPage, Page


class SpacesAPI(SpacesAPIBase):
    def create(self, *, name: str, space_embedders: list[SpaceEmbedderConfig], default_chunking_config: ChunkingConfiguration | None = None, labels: dict | None = None, owner_id: str | None = None, public_read: bool | None = False, space_id: str | None = None) -> Space:
        _kw: dict[str, Any] = {"name": name, "space_embedders": space_embedders}
        if default_chunking_config is not None: _kw["default_chunking_config"] = default_chunking_config
        if labels is not None: _kw["labels"] = labels
        if owner_id is not None: _kw["owner_id"] = owner_id
        if public_read is not None: _kw["public_read"] = public_read
        if space_id is not None: _kw["space_id"] = space_id
        apply_convenience_transforms(("spaces", "create"), _kw)
        return super().create(**_kw)

    def list(self, *, labels: dict[str, str] | None = None, name_filter: str | None = None, owner_id: str | None = None, sort_by: str | None = None, sort_order: SortOrder | None = None, page_size: int | None = None, max_items: int | None = None, next_token: str | None = None) -> Page[Space]:
        _kw: dict[str, Any] = {}
        if labels is not None: _kw["labels"] = labels
        if name_filter is not None: _kw["name_filter"] = name_filter
        if owner_id is not None: _kw["owner_id"] = owner_id
        if sort_by is not None: _kw["sort_by"] = sort_by
        if sort_order is not None: _kw["sort_order"] = sort_order
        if page_size is not None: _kw["page_size"] = page_size
        if max_items is not None: _kw["max_items"] = max_items
        if next_token is not None: _kw["next_token"] = next_token
        max_items_val = _transform_list_kwargs(_kw)
        page = super().list(**_kw)
        if max_items_val is not None:
            page._max_items = max_items_val
            page.data = page.data[:max_items_val]
        return page



class AsyncSpacesAPI(AsyncSpacesAPIBase):
    async def create(self, *, name: str, space_embedders: list[SpaceEmbedderConfig], default_chunking_config: ChunkingConfiguration | None = None, labels: dict | None = None, owner_id: str | None = None, public_read: bool | None = False, space_id: str | None = None) -> Space:
        _kw: dict[str, Any] = {"name": name, "space_embedders": space_embedders}
        if default_chunking_config is not None: _kw["default_chunking_config"] = default_chunking_config
        if labels is not None: _kw["labels"] = labels
        if owner_id is not None: _kw["owner_id"] = owner_id
        if public_read is not None: _kw["public_read"] = public_read
        if space_id is not None: _kw["space_id"] = space_id
        apply_convenience_transforms(("spaces", "create"), _kw)
        return await super().create(**_kw)

    async def list(self, *, labels: dict[str, str] | None = None, name_filter: str | None = None, owner_id: str | None = None, sort_by: str | None = None, sort_order: SortOrder | None = None, page_size: int | None = None, max_items: int | None = None, next_token: str | None = None) -> AsyncPage[Space]:
        _kw: dict[str, Any] = {}
        if labels is not None: _kw["labels"] = labels
        if name_filter is not None: _kw["name_filter"] = name_filter
        if owner_id is not None: _kw["owner_id"] = owner_id
        if sort_by is not None: _kw["sort_by"] = sort_by
        if sort_order is not None: _kw["sort_order"] = sort_order
        if page_size is not None: _kw["page_size"] = page_size
        if max_items is not None: _kw["max_items"] = max_items
        if next_token is not None: _kw["next_token"] = next_token
        max_items_val = _transform_list_kwargs(_kw)
        page = await super().list(**_kw)
        if max_items_val is not None:
            page._max_items = max_items_val
            page.data = page.data[:max_items_val]
        return page

