# SPDX-FileCopyrightText: 2026 aas-client3.2-python AUTHORS
#
# SPDX-License-Identifier: MIT
"""
Provide the results of the queries which are not formalized by aas-core3.2.
A query in the AAS Query Language gives the full objects by default, or only their
identifiers if it states ``"$select": "id"``. aas-core3.2 de-serializes the pages
of the objects (such as :py:class:`aas_core3_2.types.GetSubmodelsResult`), but not
the pages of the identifiers, since a page in the OpenAPI holds either an object or
a string as an item. Hence the client gives the pages of the identifiers as
:py:class:`IdsResult`.
"""
from typing import Iterator, List, Optional
import aas_core3_2.types as aas_types
[docs]
class IdsResult:
"""
Represent a page of the identifiers given by a query with ``"$select": "id"``.
The class follows :py:class:`aas_client3_2.pagination.Page`, so that the pages
can be followed with :py:func:`aas_client3_2.pagination.iterate`.
"""
#: Cursor to the next page
paging_metadata: aas_types.PagingMetadata
#: Identifiers of the matching objects in the page
result: Optional[List[str]]
[docs]
def __init__(
self,
paging_metadata: aas_types.PagingMetadata,
result: Optional[List[str]] = None,
) -> None:
"""Initialize with the given values."""
self.paging_metadata = paging_metadata
self.result = result
[docs]
def over_result_or_empty(self) -> Iterator[str]:
"""Yield from :py:attr:`.result` if set."""
if self.result is not None:
yield from self.result
[docs]
def __repr__(self) -> str:
"""Represent the page for debugging."""
return (
f"{self.__class__.__name__}("
f"paging_metadata=PagingMetadata(cursor={self.paging_metadata.cursor!r}), "
f"result={self.result!r})"
)