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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from .raw_client import AsyncRawProjectsClient, RawProjectsClient
from .types.api_key_deletion_response import ApiKeyDeletionResponse
from .types.api_key_list import ApiKeyList
from .types.api_key_response import ApiKeyResponse
from .types.project import Project
from .types.project_deletion_response import ProjectDeletionResponse
from .types.projects import Projects

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


class ProjectsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawProjectsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawProjectsClient
        """
        return self._raw_client

    def get(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> Projects:
        """
        Get Project associated with API key (requires project-scoped API key). You can use GET /api/public/organizations/projects to get all projects with an organization-scoped key.

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

        Returns
        -------
        Projects

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

    def create(
        self,
        *,
        name: str,
        retention: int,
        metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Project:
        """
        Create a new project (requires organization-scoped API key)

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

        retention : int
            Number of days to retain data. Must be 0 or at least 3 days. Requires data-retention entitlement for non-zero values. Optional.

        metadata : typing.Optional[typing.Dict[str, typing.Any]]
            Optional metadata for the project

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

        Returns
        -------
        Project

        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.projects.create(
            name="name",
            retention=1,
        )
        """
        _response = self._raw_client.create(
            name=name,
            retention=retention,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    def update(
        self,
        project_id: str,
        *,
        name: str,
        metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        retention: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Project:
        """
        Update a project by ID (requires organization-scoped API key).

        Parameters
        ----------
        project_id : str

        name : str

        metadata : typing.Optional[typing.Dict[str, typing.Any]]
            Optional metadata for the project

        retention : typing.Optional[int]
            Number of days to retain data.
            Must be 0 or at least 3 days.
            Requires data-retention entitlement for non-zero values.
            Optional. Will retain existing retention setting if omitted.

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

        Returns
        -------
        Project

        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.projects.update(
            project_id="projectId",
            name="name",
        )
        """
        _response = self._raw_client.update(
            project_id,
            name=name,
            metadata=metadata,
            retention=retention,
            request_options=request_options,
        )
        return _response.data

    def delete(
        self,
        project_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ProjectDeletionResponse:
        """
        Delete a project by ID (requires organization-scoped API key). Project deletion is processed asynchronously.

        Parameters
        ----------
        project_id : str

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

        Returns
        -------
        ProjectDeletionResponse

        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.projects.delete(
            project_id="projectId",
        )
        """
        _response = self._raw_client.delete(project_id, request_options=request_options)
        return _response.data

    def get_api_keys(
        self,
        project_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyList:
        """
        Get all API keys for a project (requires organization-scoped API key)

        Parameters
        ----------
        project_id : str

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

        Returns
        -------
        ApiKeyList

        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.projects.get_api_keys(
            project_id="projectId",
        )
        """
        _response = self._raw_client.get_api_keys(
            project_id, request_options=request_options
        )
        return _response.data

    def create_api_key(
        self,
        project_id: str,
        *,
        note: typing.Optional[str] = OMIT,
        public_key: typing.Optional[str] = OMIT,
        secret_key: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyResponse:
        """
        Create a new API key for a project (requires organization-scoped API key)

        Parameters
        ----------
        project_id : str

        note : typing.Optional[str]
            Optional note for the API key

        public_key : typing.Optional[str]
            Optional predefined public key. Must start with 'pk-lf-'. If provided, secretKey must also be provided.

        secret_key : typing.Optional[str]
            Optional predefined secret key. Must start with 'sk-lf-'. If provided, publicKey must also be provided.

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

        Returns
        -------
        ApiKeyResponse

        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.projects.create_api_key(
            project_id="projectId",
        )
        """
        _response = self._raw_client.create_api_key(
            project_id,
            note=note,
            public_key=public_key,
            secret_key=secret_key,
            request_options=request_options,
        )
        return _response.data

    def delete_api_key(
        self,
        project_id: str,
        api_key_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyDeletionResponse:
        """
        Delete an API key for a project (requires organization-scoped API key)

        Parameters
        ----------
        project_id : str

        api_key_id : str

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

        Returns
        -------
        ApiKeyDeletionResponse

        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.projects.delete_api_key(
            project_id="projectId",
            api_key_id="apiKeyId",
        )
        """
        _response = self._raw_client.delete_api_key(
            project_id, api_key_id, request_options=request_options
        )
        return _response.data


class AsyncProjectsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawProjectsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawProjectsClient
        """
        return self._raw_client

    async def get(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> Projects:
        """
        Get Project associated with API key (requires project-scoped API key). You can use GET /api/public/organizations/projects to get all projects with an organization-scoped key.

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

        Returns
        -------
        Projects

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


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

    async def create(
        self,
        *,
        name: str,
        retention: int,
        metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Project:
        """
        Create a new project (requires organization-scoped API key)

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

        retention : int
            Number of days to retain data. Must be 0 or at least 3 days. Requires data-retention entitlement for non-zero values. Optional.

        metadata : typing.Optional[typing.Dict[str, typing.Any]]
            Optional metadata for the project

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

        Returns
        -------
        Project

        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.projects.create(
                name="name",
                retention=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            name=name,
            retention=retention,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    async def update(
        self,
        project_id: str,
        *,
        name: str,
        metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        retention: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Project:
        """
        Update a project by ID (requires organization-scoped API key).

        Parameters
        ----------
        project_id : str

        name : str

        metadata : typing.Optional[typing.Dict[str, typing.Any]]
            Optional metadata for the project

        retention : typing.Optional[int]
            Number of days to retain data.
            Must be 0 or at least 3 days.
            Requires data-retention entitlement for non-zero values.
            Optional. Will retain existing retention setting if omitted.

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

        Returns
        -------
        Project

        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.projects.update(
                project_id="projectId",
                name="name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            project_id,
            name=name,
            metadata=metadata,
            retention=retention,
            request_options=request_options,
        )
        return _response.data

    async def delete(
        self,
        project_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ProjectDeletionResponse:
        """
        Delete a project by ID (requires organization-scoped API key). Project deletion is processed asynchronously.

        Parameters
        ----------
        project_id : str

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

        Returns
        -------
        ProjectDeletionResponse

        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.projects.delete(
                project_id="projectId",
            )


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

    async def get_api_keys(
        self,
        project_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyList:
        """
        Get all API keys for a project (requires organization-scoped API key)

        Parameters
        ----------
        project_id : str

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

        Returns
        -------
        ApiKeyList

        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.projects.get_api_keys(
                project_id="projectId",
            )


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

    async def create_api_key(
        self,
        project_id: str,
        *,
        note: typing.Optional[str] = OMIT,
        public_key: typing.Optional[str] = OMIT,
        secret_key: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyResponse:
        """
        Create a new API key for a project (requires organization-scoped API key)

        Parameters
        ----------
        project_id : str

        note : typing.Optional[str]
            Optional note for the API key

        public_key : typing.Optional[str]
            Optional predefined public key. Must start with 'pk-lf-'. If provided, secretKey must also be provided.

        secret_key : typing.Optional[str]
            Optional predefined secret key. Must start with 'sk-lf-'. If provided, publicKey must also be provided.

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

        Returns
        -------
        ApiKeyResponse

        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.projects.create_api_key(
                project_id="projectId",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_api_key(
            project_id,
            note=note,
            public_key=public_key,
            secret_key=secret_key,
            request_options=request_options,
        )
        return _response.data

    async def delete_api_key(
        self,
        project_id: str,
        api_key_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyDeletionResponse:
        """
        Delete an API key for a project (requires organization-scoped API key)

        Parameters
        ----------
        project_id : str

        api_key_id : str

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

        Returns
        -------
        ApiKeyDeletionResponse

        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.projects.delete_api_key(
                project_id="projectId",
                api_key_id="apiKeyId",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_api_key(
            project_id, api_key_id, request_options=request_options
        )
        return _response.data
