# 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.create_organization_invitation_response import CreateOrganizationInvitationResponse
from ..types.delete_response import DeleteResponse
from ..types.organization_invitation_response import OrganizationInvitationResponse
from ..types.organization_member_response import OrganizationMemberResponse
from ..types.organization_response import OrganizationResponse
from .raw_client import AsyncRawOrganizationsClient, RawOrganizationsClient
from .types.create_organization_invitation_request_role_slug import CreateOrganizationInvitationRequestRoleSlug
from .types.update_organization_member_request_role_slug import UpdateOrganizationMemberRequestRoleSlug

# 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 list(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[OrganizationResponse]:
        """
        List all organizations the current user belongs to.

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

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

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.organizations.list()
        """
        _response = self._raw_client.list(request_options=request_options)
        return _response.data

    def retrieve_current(self, *, request_options: typing.Optional[RequestOptions] = None) -> OrganizationResponse:
        """
        Get the current user's organization info.

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

        Returns
        -------
        OrganizationResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.organizations.retrieve_current()
        """
        _response = self._raw_client.retrieve_current(request_options=request_options)
        return _response.data

    def list_invitations(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[OrganizationInvitationResponse]:
        """
        List pending invitations for the current organization.

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

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

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.organizations.list_invitations()
        """
        _response = self._raw_client.list_invitations(request_options=request_options)
        return _response.data

    def create_invitation(
        self,
        *,
        email: str,
        role_slug: typing.Optional[CreateOrganizationInvitationRequestRoleSlug] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateOrganizationInvitationResponse:
        """
        Invite a user to the current organization. Idempotent for existing pending invites by email.

        Parameters
        ----------
        email : str
            Invitee email

        role_slug : typing.Optional[CreateOrganizationInvitationRequestRoleSlug]
            Organization role slug for the invited member

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

        Returns
        -------
        CreateOrganizationInvitationResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.organizations.create_invitation(
            email="email",
        )
        """
        _response = self._raw_client.create_invitation(
            email=email, role_slug=role_slug, request_options=request_options
        )
        return _response.data

    def revoke_invitation(
        self, invitation_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OrganizationInvitationResponse:
        """
        Revoke a pending invitation in the current organization.

        Parameters
        ----------
        invitation_id : str

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

        Returns
        -------
        OrganizationInvitationResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.organizations.revoke_invitation(
            invitation_id="invitation_id",
        )
        """
        _response = self._raw_client.revoke_invitation(invitation_id, request_options=request_options)
        return _response.data

    def resend_invitation(
        self, invitation_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OrganizationInvitationResponse:
        """
        Resend a pending invitation in the current organization.

        Parameters
        ----------
        invitation_id : str

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

        Returns
        -------
        OrganizationInvitationResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.organizations.resend_invitation(
            invitation_id="invitation_id",
        )
        """
        _response = self._raw_client.resend_invitation(invitation_id, request_options=request_options)
        return _response.data

    def list_members(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[OrganizationMemberResponse]:
        """
        List active members in the current organization.

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

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

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.organizations.list_members()
        """
        _response = self._raw_client.list_members(request_options=request_options)
        return _response.data

    def update_member(
        self,
        membership_id: str,
        *,
        role_slug: UpdateOrganizationMemberRequestRoleSlug,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> OrganizationMemberResponse:
        """
        Update a member role in the current organization.

        Parameters
        ----------
        membership_id : str

        role_slug : UpdateOrganizationMemberRequestRoleSlug
            Organization role slug for the target member

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

        Returns
        -------
        OrganizationMemberResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.organizations.update_member(
            membership_id="membership_id",
            role_slug="admin",
        )
        """
        _response = self._raw_client.update_member(membership_id, role_slug=role_slug, request_options=request_options)
        return _response.data

    def remove_member(
        self, membership_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteResponse:
        """
        Remove an active member from the current organization.

        Parameters
        ----------
        membership_id : str

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

        Returns
        -------
        DeleteResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.organizations.remove_member(
            membership_id="membership_id",
        )
        """
        _response = self._raw_client.remove_member(membership_id, 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 list(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[OrganizationResponse]:
        """
        List all organizations the current user belongs to.

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

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

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


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


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

    async def retrieve_current(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OrganizationResponse:
        """
        Get the current user's organization info.

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

        Returns
        -------
        OrganizationResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.organizations.retrieve_current()


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

    async def list_invitations(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[OrganizationInvitationResponse]:
        """
        List pending invitations for the current organization.

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

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

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.organizations.list_invitations()


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

    async def create_invitation(
        self,
        *,
        email: str,
        role_slug: typing.Optional[CreateOrganizationInvitationRequestRoleSlug] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateOrganizationInvitationResponse:
        """
        Invite a user to the current organization. Idempotent for existing pending invites by email.

        Parameters
        ----------
        email : str
            Invitee email

        role_slug : typing.Optional[CreateOrganizationInvitationRequestRoleSlug]
            Organization role slug for the invited member

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

        Returns
        -------
        CreateOrganizationInvitationResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.organizations.create_invitation(
                email="email",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_invitation(
            email=email, role_slug=role_slug, request_options=request_options
        )
        return _response.data

    async def revoke_invitation(
        self, invitation_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OrganizationInvitationResponse:
        """
        Revoke a pending invitation in the current organization.

        Parameters
        ----------
        invitation_id : str

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

        Returns
        -------
        OrganizationInvitationResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.organizations.revoke_invitation(
                invitation_id="invitation_id",
            )


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

    async def resend_invitation(
        self, invitation_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> OrganizationInvitationResponse:
        """
        Resend a pending invitation in the current organization.

        Parameters
        ----------
        invitation_id : str

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

        Returns
        -------
        OrganizationInvitationResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.organizations.resend_invitation(
                invitation_id="invitation_id",
            )


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

    async def list_members(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[OrganizationMemberResponse]:
        """
        List active members in the current organization.

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

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

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.organizations.list_members()


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

    async def update_member(
        self,
        membership_id: str,
        *,
        role_slug: UpdateOrganizationMemberRequestRoleSlug,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> OrganizationMemberResponse:
        """
        Update a member role in the current organization.

        Parameters
        ----------
        membership_id : str

        role_slug : UpdateOrganizationMemberRequestRoleSlug
            Organization role slug for the target member

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

        Returns
        -------
        OrganizationMemberResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.organizations.update_member(
                membership_id="membership_id",
                role_slug="admin",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_member(
            membership_id, role_slug=role_slug, request_options=request_options
        )
        return _response.data

    async def remove_member(
        self, membership_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteResponse:
        """
        Remove an active member from the current organization.

        Parameters
        ----------
        membership_id : str

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

        Returns
        -------
        DeleteResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.organizations.remove_member(
                membership_id="membership_id",
            )


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