# 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 ..types.invite_request import InviteRequest
from ..types.organization import Organization
from ..types.organization_details import OrganizationDetails
from .raw_client import AsyncRawOrganizationClient, RawOrganizationClient

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


class OrganizationClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawOrganizationClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawOrganizationClient
        """
        return self._raw_client

    def fetch_organization_details(
        self, org_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OrganizationDetails:
        """
        Return the details of the organization.

        Parameters
        ----------
        org_id : str

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

        Returns
        -------
        OrganizationDetails
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.organization.fetch_organization_details(
            org_id="org_id",
        )
        """
        _response = self._raw_client.fetch_organization_details(
            org_id, request_options=request_options
        )
        return _response.data

    def list_organizations(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[Organization]:
        """
        Returns a list of organizations associated with the user's session.

        Returns:
            list[Organization]: A list of organizations associated with the user's session.

        Raises:
            HTTPException: If there is an error retrieving the organizations from the database.

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

        Returns
        -------
        typing.List[Organization]
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.organization.list_organizations()
        """
        _response = self._raw_client.list_organizations(request_options=request_options)
        return _response.data

    def invite_user_to_workspace(
        self,
        org_id: str,
        workspace_id: str,
        *,
        request: typing.Sequence[InviteRequest],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Assigns a role to a user in an organization.

        Args:
            org_id (str): The ID of the organization.
            payload (InviteRequest): The payload containing the organization id, user email, and role to assign.
            workspace_id (str): The ID of the workspace.

        Returns:
            bool: True if the role was successfully assigned, False otherwise.

        Raises:
            HTTPException: If the user does not have permission to perform this action.
            HTTPException: If there is an error assigning the role to the user.

        Parameters
        ----------
        org_id : str

        workspace_id : str

        request : typing.Sequence[InviteRequest]

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

        Returns
        -------
        typing.Optional[typing.Any]
            Successful Response

        Examples
        --------
        from agenta import AgentaApi, InviteRequest

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.organization.invite_user_to_workspace(
            org_id="org_id",
            workspace_id="workspace_id",
            request=[
                InviteRequest(
                    email="email",
                )
            ],
        )
        """
        _response = self._raw_client.invite_user_to_workspace(
            org_id, workspace_id, request=request, request_options=request_options
        )
        return _response.data

    def resend_invitation(
        self,
        org_id: str,
        workspace_id: str,
        *,
        email: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Resend an invitation to a user to an Organization.

        Raises:
            HTTPException: _description_; status_code: 500
            HTTPException: Invitation not found or has expired; status_code: 400
            HTTPException: You already belong to this organization; status_code: 400

        Returns:
            JSONResponse: Resent invitation to user; status_code: 200

        Parameters
        ----------
        org_id : str

        workspace_id : str

        email : str

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

        Returns
        -------
        typing.Optional[typing.Any]
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.organization.resend_invitation(
            org_id="org_id",
            workspace_id="workspace_id",
            email="email",
        )
        """
        _response = self._raw_client.resend_invitation(
            org_id, workspace_id, email=email, request_options=request_options
        )
        return _response.data

    def accept_invitation(
        self,
        org_id: str,
        workspace_id: str,
        *,
        project_id: str,
        token: str,
        email: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Accept an invitation to an organization.

        Raises:
            HTTPException: _description_; status_code: 500
            HTTPException: Invitation not found or has expired; status_code: 400
            HTTPException: You already belong to this organization; status_code: 400

        Returns:
            JSONResponse: Accepted invitation to workspace; status_code: 200

        Parameters
        ----------
        org_id : str

        workspace_id : str

        project_id : str

        token : str

        email : str

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

        Returns
        -------
        typing.Optional[typing.Any]
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.organization.accept_invitation(
            org_id="org_id",
            workspace_id="workspace_id",
            project_id="project_id",
            token="token",
            email="email",
        )
        """
        _response = self._raw_client.accept_invitation(
            org_id,
            workspace_id,
            project_id=project_id,
            token=token,
            email=email,
            request_options=request_options,
        )
        return _response.data


class AsyncOrganizationClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawOrganizationClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawOrganizationClient
        """
        return self._raw_client

    async def fetch_organization_details(
        self, org_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OrganizationDetails:
        """
        Return the details of the organization.

        Parameters
        ----------
        org_id : str

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

        Returns
        -------
        OrganizationDetails
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.organization.fetch_organization_details(
                org_id="org_id",
            )


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

    async def list_organizations(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[Organization]:
        """
        Returns a list of organizations associated with the user's session.

        Returns:
            list[Organization]: A list of organizations associated with the user's session.

        Raises:
            HTTPException: If there is an error retrieving the organizations from the database.

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

        Returns
        -------
        typing.List[Organization]
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.organization.list_organizations()


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

    async def invite_user_to_workspace(
        self,
        org_id: str,
        workspace_id: str,
        *,
        request: typing.Sequence[InviteRequest],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Assigns a role to a user in an organization.

        Args:
            org_id (str): The ID of the organization.
            payload (InviteRequest): The payload containing the organization id, user email, and role to assign.
            workspace_id (str): The ID of the workspace.

        Returns:
            bool: True if the role was successfully assigned, False otherwise.

        Raises:
            HTTPException: If the user does not have permission to perform this action.
            HTTPException: If there is an error assigning the role to the user.

        Parameters
        ----------
        org_id : str

        workspace_id : str

        request : typing.Sequence[InviteRequest]

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

        Returns
        -------
        typing.Optional[typing.Any]
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi, InviteRequest

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.organization.invite_user_to_workspace(
                org_id="org_id",
                workspace_id="workspace_id",
                request=[
                    InviteRequest(
                        email="email",
                    )
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.invite_user_to_workspace(
            org_id, workspace_id, request=request, request_options=request_options
        )
        return _response.data

    async def resend_invitation(
        self,
        org_id: str,
        workspace_id: str,
        *,
        email: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Resend an invitation to a user to an Organization.

        Raises:
            HTTPException: _description_; status_code: 500
            HTTPException: Invitation not found or has expired; status_code: 400
            HTTPException: You already belong to this organization; status_code: 400

        Returns:
            JSONResponse: Resent invitation to user; status_code: 200

        Parameters
        ----------
        org_id : str

        workspace_id : str

        email : str

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

        Returns
        -------
        typing.Optional[typing.Any]
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.organization.resend_invitation(
                org_id="org_id",
                workspace_id="workspace_id",
                email="email",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.resend_invitation(
            org_id, workspace_id, email=email, request_options=request_options
        )
        return _response.data

    async def accept_invitation(
        self,
        org_id: str,
        workspace_id: str,
        *,
        project_id: str,
        token: str,
        email: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Accept an invitation to an organization.

        Raises:
            HTTPException: _description_; status_code: 500
            HTTPException: Invitation not found or has expired; status_code: 400
            HTTPException: You already belong to this organization; status_code: 400

        Returns:
            JSONResponse: Accepted invitation to workspace; status_code: 200

        Parameters
        ----------
        org_id : str

        workspace_id : str

        project_id : str

        token : str

        email : str

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

        Returns
        -------
        typing.Optional[typing.Any]
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.organization.accept_invitation(
                org_id="org_id",
                workspace_id="workspace_id",
                project_id="project_id",
                token="token",
                email="email",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.accept_invitation(
            org_id,
            workspace_id,
            project_id=project_id,
            token=token,
            email=email,
            request_options=request_options,
        )
        return _response.data
