# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

from ..commons.types.dataset_item import DatasetItem
from ..commons.types.dataset_status import DatasetStatus
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from .raw_client import AsyncRawDatasetItemsClient, RawDatasetItemsClient
from .types.delete_dataset_item_response import DeleteDatasetItemResponse
from .types.paginated_dataset_items import PaginatedDatasetItems

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class DatasetItemsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawDatasetItemsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawDatasetItemsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawDatasetItemsClient
        """
        return self._raw_client

    def create(
        self,
        *,
        dataset_name: str,
        input: typing.Optional[typing.Any] = OMIT,
        expected_output: typing.Optional[typing.Any] = OMIT,
        metadata: typing.Optional[typing.Any] = OMIT,
        source_trace_id: typing.Optional[str] = OMIT,
        source_observation_id: typing.Optional[str] = OMIT,
        id: typing.Optional[str] = OMIT,
        status: typing.Optional[DatasetStatus] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DatasetItem:
        """
        Create a dataset item

        Parameters
        ----------
        dataset_name : str

        input : typing.Optional[typing.Any]

        expected_output : typing.Optional[typing.Any]

        metadata : typing.Optional[typing.Any]

        source_trace_id : typing.Optional[str]

        source_observation_id : typing.Optional[str]

        id : typing.Optional[str]
            Dataset items are upserted on their id. Id needs to be unique (project-level) and cannot be reused across datasets.

        status : typing.Optional[DatasetStatus]
            Defaults to ACTIVE for newly created items

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DatasetItem

        Examples
        --------
        from langfuse import LangfuseAPI

        client = LangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )
        client.dataset_items.create(
            dataset_name="datasetName",
        )
        """
        _response = self._raw_client.create(
            dataset_name=dataset_name,
            input=input,
            expected_output=expected_output,
            metadata=metadata,
            source_trace_id=source_trace_id,
            source_observation_id=source_observation_id,
            id=id,
            status=status,
            request_options=request_options,
        )
        return _response.data

    def get(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DatasetItem:
        """
        Get a dataset item

        Parameters
        ----------
        id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DatasetItem

        Examples
        --------
        from langfuse import LangfuseAPI

        client = LangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )
        client.dataset_items.get(
            id="id",
        )
        """
        _response = self._raw_client.get(id, request_options=request_options)
        return _response.data

    def list(
        self,
        *,
        dataset_name: typing.Optional[str] = None,
        source_trace_id: typing.Optional[str] = None,
        source_observation_id: typing.Optional[str] = None,
        version: typing.Optional[dt.datetime] = None,
        page: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PaginatedDatasetItems:
        """
        Get dataset items. Optionally specify a version to get the items as they existed at that point in time.
        Note: If version parameter is provided, datasetName must also be provided.

        Parameters
        ----------
        dataset_name : typing.Optional[str]

        source_trace_id : typing.Optional[str]

        source_observation_id : typing.Optional[str]

        version : typing.Optional[dt.datetime]
            ISO 8601 timestamp (RFC 3339, Section 5.6) in UTC (e.g., "2026-01-21T14:35:42Z").
            If provided, returns state of dataset at this timestamp.
            If not provided, returns the latest version. Requires datasetName to be specified.

        page : typing.Optional[int]
            page number, starts at 1

        limit : typing.Optional[int]
            limit of items per page

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        PaginatedDatasetItems

        Examples
        --------
        from langfuse import LangfuseAPI

        client = LangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )
        client.dataset_items.list()
        """
        _response = self._raw_client.list(
            dataset_name=dataset_name,
            source_trace_id=source_trace_id,
            source_observation_id=source_observation_id,
            version=version,
            page=page,
            limit=limit,
            request_options=request_options,
        )
        return _response.data

    def delete(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteDatasetItemResponse:
        """
        Delete a dataset item and all its run items. This action is irreversible.

        Parameters
        ----------
        id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DeleteDatasetItemResponse

        Examples
        --------
        from langfuse import LangfuseAPI

        client = LangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )
        client.dataset_items.delete(
            id="id",
        )
        """
        _response = self._raw_client.delete(id, request_options=request_options)
        return _response.data


class AsyncDatasetItemsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawDatasetItemsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawDatasetItemsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawDatasetItemsClient
        """
        return self._raw_client

    async def create(
        self,
        *,
        dataset_name: str,
        input: typing.Optional[typing.Any] = OMIT,
        expected_output: typing.Optional[typing.Any] = OMIT,
        metadata: typing.Optional[typing.Any] = OMIT,
        source_trace_id: typing.Optional[str] = OMIT,
        source_observation_id: typing.Optional[str] = OMIT,
        id: typing.Optional[str] = OMIT,
        status: typing.Optional[DatasetStatus] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DatasetItem:
        """
        Create a dataset item

        Parameters
        ----------
        dataset_name : str

        input : typing.Optional[typing.Any]

        expected_output : typing.Optional[typing.Any]

        metadata : typing.Optional[typing.Any]

        source_trace_id : typing.Optional[str]

        source_observation_id : typing.Optional[str]

        id : typing.Optional[str]
            Dataset items are upserted on their id. Id needs to be unique (project-level) and cannot be reused across datasets.

        status : typing.Optional[DatasetStatus]
            Defaults to ACTIVE for newly created items

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DatasetItem

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI

        client = AsyncLangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.dataset_items.create(
                dataset_name="datasetName",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            dataset_name=dataset_name,
            input=input,
            expected_output=expected_output,
            metadata=metadata,
            source_trace_id=source_trace_id,
            source_observation_id=source_observation_id,
            id=id,
            status=status,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DatasetItem:
        """
        Get a dataset item

        Parameters
        ----------
        id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DatasetItem

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI

        client = AsyncLangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.dataset_items.get(
                id="id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get(id, request_options=request_options)
        return _response.data

    async def list(
        self,
        *,
        dataset_name: typing.Optional[str] = None,
        source_trace_id: typing.Optional[str] = None,
        source_observation_id: typing.Optional[str] = None,
        version: typing.Optional[dt.datetime] = None,
        page: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PaginatedDatasetItems:
        """
        Get dataset items. Optionally specify a version to get the items as they existed at that point in time.
        Note: If version parameter is provided, datasetName must also be provided.

        Parameters
        ----------
        dataset_name : typing.Optional[str]

        source_trace_id : typing.Optional[str]

        source_observation_id : typing.Optional[str]

        version : typing.Optional[dt.datetime]
            ISO 8601 timestamp (RFC 3339, Section 5.6) in UTC (e.g., "2026-01-21T14:35:42Z").
            If provided, returns state of dataset at this timestamp.
            If not provided, returns the latest version. Requires datasetName to be specified.

        page : typing.Optional[int]
            page number, starts at 1

        limit : typing.Optional[int]
            limit of items per page

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        PaginatedDatasetItems

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI

        client = AsyncLangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.dataset_items.list()


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            dataset_name=dataset_name,
            source_trace_id=source_trace_id,
            source_observation_id=source_observation_id,
            version=version,
            page=page,
            limit=limit,
            request_options=request_options,
        )
        return _response.data

    async def delete(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteDatasetItemResponse:
        """
        Delete a dataset item and all its run items. This action is irreversible.

        Parameters
        ----------
        id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        DeleteDatasetItemResponse

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI

        client = AsyncLangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.dataset_items.delete(
                id="id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete(id, request_options=request_options)
        return _response.data
