# 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 AsyncRawOrganizationsClient, RawOrganizationsClient
from .types.membership_deletion_response import MembershipDeletionResponse
from .types.membership_response import MembershipResponse
from .types.membership_role import MembershipRole
from .types.memberships_response import MembershipsResponse
from .types.organization_api_keys_response import OrganizationApiKeysResponse
from .types.organization_projects_response import OrganizationProjectsResponse

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


class OrganizationsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawOrganizationsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawOrganizationsClient
        """
        return self._raw_client

    def get_organization_memberships(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> MembershipsResponse:
        """
        Get all memberships for the organization associated with the API key (requires organization-scoped API key)

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

        Returns
        -------
        MembershipsResponse

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

    def update_organization_membership(
        self,
        *,
        user_id: str,
        role: MembershipRole,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MembershipResponse:
        """
        Create or update a membership for the organization associated with the API key (requires organization-scoped API key)

        Parameters
        ----------
        user_id : str

        role : MembershipRole

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

        Returns
        -------
        MembershipResponse

        Examples
        --------
        from langfuse import LangfuseAPI
        from langfuse.organizations import MembershipRole

        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.organizations.update_organization_membership(
            user_id="userId",
            role=MembershipRole.OWNER,
        )
        """
        _response = self._raw_client.update_organization_membership(
            user_id=user_id, role=role, request_options=request_options
        )
        return _response.data

    def delete_organization_membership(
        self, *, user_id: str, request_options: typing.Optional[RequestOptions] = None
    ) -> MembershipDeletionResponse:
        """
        Delete a membership from the organization associated with the API key (requires organization-scoped API key)

        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        MembershipDeletionResponse

        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.organizations.delete_organization_membership(
            user_id="userId",
        )
        """
        _response = self._raw_client.delete_organization_membership(
            user_id=user_id, request_options=request_options
        )
        return _response.data

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

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

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

        Returns
        -------
        MembershipsResponse

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

    def update_project_membership(
        self,
        project_id: str,
        *,
        user_id: str,
        role: MembershipRole,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MembershipResponse:
        """
        Create or update a membership for a specific project (requires organization-scoped API key). The user must already be a member of the organization.

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

        user_id : str

        role : MembershipRole

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

        Returns
        -------
        MembershipResponse

        Examples
        --------
        from langfuse import LangfuseAPI
        from langfuse.organizations import MembershipRole

        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.organizations.update_project_membership(
            project_id="projectId",
            user_id="userId",
            role=MembershipRole.OWNER,
        )
        """
        _response = self._raw_client.update_project_membership(
            project_id, user_id=user_id, role=role, request_options=request_options
        )
        return _response.data

    def delete_project_membership(
        self,
        project_id: str,
        *,
        user_id: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MembershipDeletionResponse:
        """
        Delete a membership from a specific project (requires organization-scoped API key). The user must be a member of the organization.

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

        user_id : str

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

        Returns
        -------
        MembershipDeletionResponse

        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.organizations.delete_project_membership(
            project_id="projectId",
            user_id="userId",
        )
        """
        _response = self._raw_client.delete_project_membership(
            project_id, user_id=user_id, request_options=request_options
        )
        return _response.data

    def get_organization_projects(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OrganizationProjectsResponse:
        """
        Get all projects for the organization associated with the API key (requires organization-scoped API key)

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

        Returns
        -------
        OrganizationProjectsResponse

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

    def get_organization_api_keys(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OrganizationApiKeysResponse:
        """
        Get all API keys for the organization associated with the API key (requires organization-scoped API key)

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

        Returns
        -------
        OrganizationApiKeysResponse

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


class AsyncOrganizationsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawOrganizationsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawOrganizationsClient
        """
        return self._raw_client

    async def get_organization_memberships(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> MembershipsResponse:
        """
        Get all memberships for the organization associated with the API key (requires organization-scoped API key)

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

        Returns
        -------
        MembershipsResponse

        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.organizations.get_organization_memberships()


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

    async def update_organization_membership(
        self,
        *,
        user_id: str,
        role: MembershipRole,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MembershipResponse:
        """
        Create or update a membership for the organization associated with the API key (requires organization-scoped API key)

        Parameters
        ----------
        user_id : str

        role : MembershipRole

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

        Returns
        -------
        MembershipResponse

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI
        from langfuse.organizations import MembershipRole

        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.organizations.update_organization_membership(
                user_id="userId",
                role=MembershipRole.OWNER,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_organization_membership(
            user_id=user_id, role=role, request_options=request_options
        )
        return _response.data

    async def delete_organization_membership(
        self, *, user_id: str, request_options: typing.Optional[RequestOptions] = None
    ) -> MembershipDeletionResponse:
        """
        Delete a membership from the organization associated with the API key (requires organization-scoped API key)

        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        MembershipDeletionResponse

        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.organizations.delete_organization_membership(
                user_id="userId",
            )


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

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

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

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

        Returns
        -------
        MembershipsResponse

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


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

    async def update_project_membership(
        self,
        project_id: str,
        *,
        user_id: str,
        role: MembershipRole,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MembershipResponse:
        """
        Create or update a membership for a specific project (requires organization-scoped API key). The user must already be a member of the organization.

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

        user_id : str

        role : MembershipRole

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

        Returns
        -------
        MembershipResponse

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI
        from langfuse.organizations import MembershipRole

        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.organizations.update_project_membership(
                project_id="projectId",
                user_id="userId",
                role=MembershipRole.OWNER,
            )


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

    async def delete_project_membership(
        self,
        project_id: str,
        *,
        user_id: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MembershipDeletionResponse:
        """
        Delete a membership from a specific project (requires organization-scoped API key). The user must be a member of the organization.

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

        user_id : str

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

        Returns
        -------
        MembershipDeletionResponse

        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.organizations.delete_project_membership(
                project_id="projectId",
                user_id="userId",
            )


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

    async def get_organization_projects(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OrganizationProjectsResponse:
        """
        Get all projects for the organization associated with the API key (requires organization-scoped API key)

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

        Returns
        -------
        OrganizationProjectsResponse

        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.organizations.get_organization_projects()


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

    async def get_organization_api_keys(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OrganizationApiKeysResponse:
        """
        Get all API keys for the organization associated with the API key (requires organization-scoped API key)

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

        Returns
        -------
        OrganizationApiKeysResponse

        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.organizations.get_organization_api_keys()


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