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

import typing

from ..commons.types.config_category import ConfigCategory
from ..commons.types.score_config import ScoreConfig
from ..commons.types.score_config_data_type import ScoreConfigDataType
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from .raw_client import AsyncRawScoreConfigsClient, RawScoreConfigsClient
from .types.score_configs import ScoreConfigs

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


class ScoreConfigsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawScoreConfigsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawScoreConfigsClient
        """
        return self._raw_client

    def create(
        self,
        *,
        name: str,
        data_type: ScoreConfigDataType,
        categories: typing.Optional[typing.Sequence[ConfigCategory]] = OMIT,
        min_value: typing.Optional[float] = OMIT,
        max_value: typing.Optional[float] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScoreConfig:
        """
        Create a score configuration (config). Score configs are used to define the structure of scores

        Parameters
        ----------
        name : str

        data_type : ScoreConfigDataType

        categories : typing.Optional[typing.Sequence[ConfigCategory]]
            Configure custom categories for categorical scores. Pass a list of objects with `label` and `value` properties. Categories are autogenerated for boolean configs and cannot be passed

        min_value : typing.Optional[float]
            Configure a minimum value for numerical scores. If not set, the minimum value defaults to -∞

        max_value : typing.Optional[float]
            Configure a maximum value for numerical scores. If not set, the maximum value defaults to +∞

        description : typing.Optional[str]
            Description is shown across the Langfuse UI and can be used to e.g. explain the config categories in detail, why a numeric range was set, or provide additional context on config name or usage

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

        Returns
        -------
        ScoreConfig

        Examples
        --------
        from langfuse import LangfuseAPI
        from langfuse.commons import ScoreConfigDataType

        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.score_configs.create(
            name="name",
            data_type=ScoreConfigDataType.NUMERIC,
        )
        """
        _response = self._raw_client.create(
            name=name,
            data_type=data_type,
            categories=categories,
            min_value=min_value,
            max_value=max_value,
            description=description,
            request_options=request_options,
        )
        return _response.data

    def get(
        self,
        *,
        page: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScoreConfigs:
        """
        Get all score configs

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

        limit : typing.Optional[int]
            Limit of items per page. If you encounter api issues due to too large page sizes, try to reduce the limit

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

        Returns
        -------
        ScoreConfigs

        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.score_configs.get()
        """
        _response = self._raw_client.get(
            page=page, limit=limit, request_options=request_options
        )
        return _response.data

    def get_by_id(
        self, config_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ScoreConfig:
        """
        Get a score config

        Parameters
        ----------
        config_id : str
            The unique langfuse identifier of a score config

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

        Returns
        -------
        ScoreConfig

        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.score_configs.get_by_id(
            config_id="configId",
        )
        """
        _response = self._raw_client.get_by_id(
            config_id, request_options=request_options
        )
        return _response.data

    def update(
        self,
        config_id: str,
        *,
        is_archived: typing.Optional[bool] = OMIT,
        name: typing.Optional[str] = OMIT,
        categories: typing.Optional[typing.Sequence[ConfigCategory]] = OMIT,
        min_value: typing.Optional[float] = OMIT,
        max_value: typing.Optional[float] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScoreConfig:
        """
        Update a score config

        Parameters
        ----------
        config_id : str
            The unique langfuse identifier of a score config

        is_archived : typing.Optional[bool]
            The status of the score config showing if it is archived or not

        name : typing.Optional[str]
            The name of the score config

        categories : typing.Optional[typing.Sequence[ConfigCategory]]
            Configure custom categories for categorical scores. Pass a list of objects with `label` and `value` properties. Categories are autogenerated for boolean configs and cannot be passed

        min_value : typing.Optional[float]
            Configure a minimum value for numerical scores. If not set, the minimum value defaults to -∞

        max_value : typing.Optional[float]
            Configure a maximum value for numerical scores. If not set, the maximum value defaults to +∞

        description : typing.Optional[str]
            Description is shown across the Langfuse UI and can be used to e.g. explain the config categories in detail, why a numeric range was set, or provide additional context on config name or usage

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

        Returns
        -------
        ScoreConfig

        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.score_configs.update(
            config_id="configId",
        )
        """
        _response = self._raw_client.update(
            config_id,
            is_archived=is_archived,
            name=name,
            categories=categories,
            min_value=min_value,
            max_value=max_value,
            description=description,
            request_options=request_options,
        )
        return _response.data


class AsyncScoreConfigsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawScoreConfigsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawScoreConfigsClient
        """
        return self._raw_client

    async def create(
        self,
        *,
        name: str,
        data_type: ScoreConfigDataType,
        categories: typing.Optional[typing.Sequence[ConfigCategory]] = OMIT,
        min_value: typing.Optional[float] = OMIT,
        max_value: typing.Optional[float] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScoreConfig:
        """
        Create a score configuration (config). Score configs are used to define the structure of scores

        Parameters
        ----------
        name : str

        data_type : ScoreConfigDataType

        categories : typing.Optional[typing.Sequence[ConfigCategory]]
            Configure custom categories for categorical scores. Pass a list of objects with `label` and `value` properties. Categories are autogenerated for boolean configs and cannot be passed

        min_value : typing.Optional[float]
            Configure a minimum value for numerical scores. If not set, the minimum value defaults to -∞

        max_value : typing.Optional[float]
            Configure a maximum value for numerical scores. If not set, the maximum value defaults to +∞

        description : typing.Optional[str]
            Description is shown across the Langfuse UI and can be used to e.g. explain the config categories in detail, why a numeric range was set, or provide additional context on config name or usage

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

        Returns
        -------
        ScoreConfig

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI
        from langfuse.commons import ScoreConfigDataType

        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.score_configs.create(
                name="name",
                data_type=ScoreConfigDataType.NUMERIC,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            name=name,
            data_type=data_type,
            categories=categories,
            min_value=min_value,
            max_value=max_value,
            description=description,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self,
        *,
        page: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScoreConfigs:
        """
        Get all score configs

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

        limit : typing.Optional[int]
            Limit of items per page. If you encounter api issues due to too large page sizes, try to reduce the limit

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

        Returns
        -------
        ScoreConfigs

        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.score_configs.get()


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

    async def get_by_id(
        self, config_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ScoreConfig:
        """
        Get a score config

        Parameters
        ----------
        config_id : str
            The unique langfuse identifier of a score config

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

        Returns
        -------
        ScoreConfig

        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.score_configs.get_by_id(
                config_id="configId",
            )


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

    async def update(
        self,
        config_id: str,
        *,
        is_archived: typing.Optional[bool] = OMIT,
        name: typing.Optional[str] = OMIT,
        categories: typing.Optional[typing.Sequence[ConfigCategory]] = OMIT,
        min_value: typing.Optional[float] = OMIT,
        max_value: typing.Optional[float] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ScoreConfig:
        """
        Update a score config

        Parameters
        ----------
        config_id : str
            The unique langfuse identifier of a score config

        is_archived : typing.Optional[bool]
            The status of the score config showing if it is archived or not

        name : typing.Optional[str]
            The name of the score config

        categories : typing.Optional[typing.Sequence[ConfigCategory]]
            Configure custom categories for categorical scores. Pass a list of objects with `label` and `value` properties. Categories are autogenerated for boolean configs and cannot be passed

        min_value : typing.Optional[float]
            Configure a minimum value for numerical scores. If not set, the minimum value defaults to -∞

        max_value : typing.Optional[float]
            Configure a maximum value for numerical scores. If not set, the maximum value defaults to +∞

        description : typing.Optional[str]
            Description is shown across the Langfuse UI and can be used to e.g. explain the config categories in detail, why a numeric range was set, or provide additional context on config name or usage

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

        Returns
        -------
        ScoreConfig

        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.score_configs.update(
                config_id="configId",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            config_id,
            is_archived=is_archived,
            name=name,
            categories=categories,
            min_value=min_value,
            max_value=max_value,
            description=description,
            request_options=request_options,
        )
        return _response.data
