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

from __future__ import annotations

import datetime as dt
import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.default_role import DefaultRole
from ..types.lse_organization import LseOrganization
from ..types.organization_id import OrganizationId
from ..types.organization_invite import OrganizationInvite
from ..types.role9e7enum import Role9E7Enum
from .raw_client import AsyncRawOrganizationsClient, RawOrganizationsClient

if typing.TYPE_CHECKING:
    from .invites.client import AsyncInvitesClient, InvitesClient
    from .member_tags.client import AsyncMemberTagsClient, MemberTagsClient
    from .members.client import AsyncMembersClient, MembersClient
    from .permissions.client import AsyncPermissionsClient, PermissionsClient
# 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)
        self._client_wrapper = client_wrapper
        self._invites: typing.Optional[InvitesClient] = None
        self._member_tags: typing.Optional[MemberTagsClient] = None
        self._members: typing.Optional[MembersClient] = None
        self._permissions: typing.Optional[PermissionsClient] = None

    @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 reset_token(self, *, request_options: typing.Optional[RequestOptions] = None) -> OrganizationInvite:
        """
        Reset the token used in the invitation link to invite someone to an organization.

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

        Returns
        -------
        OrganizationInvite


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.organizations.reset_token()
        """
        _response = self._raw_client.reset_token(request_options=request_options)
        return _response.data

    def list(
        self, *, ordering: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[OrganizationId]:
        """

                Return a list of the organizations you've created or that you have access to.


        Parameters
        ----------
        ordering : typing.Optional[str]
            Which field to use when ordering the results.

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

        Returns
        -------
        typing.List[OrganizationId]


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.organizations.list()
        """
        _response = self._raw_client.list(ordering=ordering, request_options=request_options)
        return _response.data

    def get(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> LseOrganization:
        """
        Retrieve the settings for a specific organization by ID.

        Parameters
        ----------
        id : int

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

        Returns
        -------
        LseOrganization


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.organizations.get(
            id=1,
        )
        """
        _response = self._raw_client.get(id, request_options=request_options)
        return _response.data

    def update(
        self,
        id: int,
        *,
        contact_info: typing.Optional[str] = OMIT,
        created_by: typing.Optional[int] = OMIT,
        custom_scripts_enabled: typing.Optional[bool] = OMIT,
        email_notification_settings: typing.Optional[typing.Any] = OMIT,
        embed_domains: typing.Optional[typing.Sequence[typing.Dict[str, str]]] = OMIT,
        embed_settings: typing.Optional[typing.Any] = OMIT,
        title: typing.Optional[str] = OMIT,
        token: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> LseOrganization:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Update organization details including title, embed domains, and Plugins settings.

        Parameters
        ----------
        id : int

        contact_info : typing.Optional[str]

        created_by : typing.Optional[int]

        custom_scripts_enabled : typing.Optional[bool]
            Plugins

        email_notification_settings : typing.Optional[typing.Any]
            Email Notification Settings

        embed_domains : typing.Optional[typing.Sequence[typing.Dict[str, str]]]
            Supported domains

        embed_settings : typing.Optional[typing.Any]
            Public Verification Key and Public Verification Algorithms configuration

        title : typing.Optional[str]
            Organization name

        token : typing.Optional[str]

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

        Returns
        -------
        LseOrganization


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.organizations.update(
            id=1,
        )
        """
        _response = self._raw_client.update(
            id,
            contact_info=contact_info,
            created_by=created_by,
            custom_scripts_enabled=custom_scripts_enabled,
            email_notification_settings=email_notification_settings,
            embed_domains=embed_domains,
            embed_settings=embed_settings,
            title=title,
            token=token,
            request_options=request_options,
        )
        return _response.data

    def update_default_role(
        self,
        id: int,
        *,
        annotator_reviewer_firewall_enabled_at: typing.Optional[dt.datetime] = OMIT,
        custom_scripts_enabled_at: typing.Optional[dt.datetime] = OMIT,
        default_role: typing.Optional[Role9E7Enum] = OMIT,
        email_notification_settings: typing.Optional[typing.Any] = OMIT,
        embed_domains: typing.Optional[typing.Any] = OMIT,
        embed_settings: typing.Optional[typing.Any] = OMIT,
        external_id: typing.Optional[str] = OMIT,
        extra_data_on_activity_logs: typing.Optional[bool] = OMIT,
        label_stream_navigation_disabled_at: typing.Optional[dt.datetime] = OMIT,
        organization: typing.Optional[int] = OMIT,
        read_only_quick_view_enabled_at: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DefaultRole:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Update the default role for members of a specific organization.

        Parameters
        ----------
        id : int

        annotator_reviewer_firewall_enabled_at : typing.Optional[dt.datetime]
            Set to current time to restrict data sharing between annotators and reviewers in the label stream, review stream, and notifications (which will be disabled). In these settings, information about annotator and reviewer identity is suppressed in the UI.

        custom_scripts_enabled_at : typing.Optional[dt.datetime]
            Set to current time to enable custom scripts (Plugins) for this organization. Can only be enabled if no organization members are active members of any other organizations; otherwise an error will be raised. If this occurs, contact the LEAP team for assistance with enabling custom scripts (Plugins).

        default_role : typing.Optional[Role9E7Enum]
            Default membership role for invited users

            * `OW` - Owner
            * `AD` - Administrator
            * `MA` - Manager
            * `RE` - Reviewer
            * `AN` - Annotator
            * `DI` - Deactivated
            * `NO` - Not Activated

        email_notification_settings : typing.Optional[typing.Any]
            Email notification settings for this organization. Controls which email notifications users can receive. Structure: {"notifications_allowed": {"notification_type": bool}}

        embed_domains : typing.Optional[typing.Any]
            List of objects: {"domain": "example.com"}. Used for CSP header on /embed routes.

        embed_settings : typing.Optional[typing.Any]
            Embed settings for this organization

        external_id : typing.Optional[str]
            External ID to uniquely identify this organization

        extra_data_on_activity_logs : typing.Optional[bool]

        label_stream_navigation_disabled_at : typing.Optional[dt.datetime]
            Set to current time to disable the label stream navigation for this organization. This will prevent users from going back in the label stream to view previous labels.

        organization : typing.Optional[int]
            A unique integer value identifying this organization.

        read_only_quick_view_enabled_at : typing.Optional[dt.datetime]
            Set to current time to prevent creating or editing annotations in quick view.

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

        Returns
        -------
        DefaultRole


        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.organizations.update_default_role(
            id=1,
        )
        """
        _response = self._raw_client.update_default_role(
            id,
            annotator_reviewer_firewall_enabled_at=annotator_reviewer_firewall_enabled_at,
            custom_scripts_enabled_at=custom_scripts_enabled_at,
            default_role=default_role,
            email_notification_settings=email_notification_settings,
            embed_domains=embed_domains,
            embed_settings=embed_settings,
            external_id=external_id,
            extra_data_on_activity_logs=extra_data_on_activity_logs,
            label_stream_navigation_disabled_at=label_stream_navigation_disabled_at,
            organization=organization,
            read_only_quick_view_enabled_at=read_only_quick_view_enabled_at,
            request_options=request_options,
        )
        return _response.data

    @property
    def invites(self):
        if self._invites is None:
            from .invites.client import InvitesClient  # noqa: E402

            self._invites = InvitesClient(client_wrapper=self._client_wrapper)
        return self._invites

    @property
    def member_tags(self):
        if self._member_tags is None:
            from .member_tags.client import MemberTagsClient  # noqa: E402

            self._member_tags = MemberTagsClient(client_wrapper=self._client_wrapper)
        return self._member_tags

    @property
    def members(self):
        if self._members is None:
            from .members.client import MembersClient  # noqa: E402

            self._members = MembersClient(client_wrapper=self._client_wrapper)
        return self._members

    @property
    def permissions(self):
        if self._permissions is None:
            from .permissions.client import PermissionsClient  # noqa: E402

            self._permissions = PermissionsClient(client_wrapper=self._client_wrapper)
        return self._permissions


class AsyncOrganizationsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawOrganizationsClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._invites: typing.Optional[AsyncInvitesClient] = None
        self._member_tags: typing.Optional[AsyncMemberTagsClient] = None
        self._members: typing.Optional[AsyncMembersClient] = None
        self._permissions: typing.Optional[AsyncPermissionsClient] = None

    @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 reset_token(self, *, request_options: typing.Optional[RequestOptions] = None) -> OrganizationInvite:
        """
        Reset the token used in the invitation link to invite someone to an organization.

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

        Returns
        -------
        OrganizationInvite


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


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


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

    async def list(
        self, *, ordering: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[OrganizationId]:
        """

                Return a list of the organizations you've created or that you have access to.


        Parameters
        ----------
        ordering : typing.Optional[str]
            Which field to use when ordering the results.

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

        Returns
        -------
        typing.List[OrganizationId]


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


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


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

    async def get(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> LseOrganization:
        """
        Retrieve the settings for a specific organization by ID.

        Parameters
        ----------
        id : int

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

        Returns
        -------
        LseOrganization


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.organizations.get(
                id=1,
            )


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

    async def update(
        self,
        id: int,
        *,
        contact_info: typing.Optional[str] = OMIT,
        created_by: typing.Optional[int] = OMIT,
        custom_scripts_enabled: typing.Optional[bool] = OMIT,
        email_notification_settings: typing.Optional[typing.Any] = OMIT,
        embed_domains: typing.Optional[typing.Sequence[typing.Dict[str, str]]] = OMIT,
        embed_settings: typing.Optional[typing.Any] = OMIT,
        title: typing.Optional[str] = OMIT,
        token: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> LseOrganization:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Update organization details including title, embed domains, and Plugins settings.

        Parameters
        ----------
        id : int

        contact_info : typing.Optional[str]

        created_by : typing.Optional[int]

        custom_scripts_enabled : typing.Optional[bool]
            Plugins

        email_notification_settings : typing.Optional[typing.Any]
            Email Notification Settings

        embed_domains : typing.Optional[typing.Sequence[typing.Dict[str, str]]]
            Supported domains

        embed_settings : typing.Optional[typing.Any]
            Public Verification Key and Public Verification Algorithms configuration

        title : typing.Optional[str]
            Organization name

        token : typing.Optional[str]

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

        Returns
        -------
        LseOrganization


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.organizations.update(
                id=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            id,
            contact_info=contact_info,
            created_by=created_by,
            custom_scripts_enabled=custom_scripts_enabled,
            email_notification_settings=email_notification_settings,
            embed_domains=embed_domains,
            embed_settings=embed_settings,
            title=title,
            token=token,
            request_options=request_options,
        )
        return _response.data

    async def update_default_role(
        self,
        id: int,
        *,
        annotator_reviewer_firewall_enabled_at: typing.Optional[dt.datetime] = OMIT,
        custom_scripts_enabled_at: typing.Optional[dt.datetime] = OMIT,
        default_role: typing.Optional[Role9E7Enum] = OMIT,
        email_notification_settings: typing.Optional[typing.Any] = OMIT,
        embed_domains: typing.Optional[typing.Any] = OMIT,
        embed_settings: typing.Optional[typing.Any] = OMIT,
        external_id: typing.Optional[str] = OMIT,
        extra_data_on_activity_logs: typing.Optional[bool] = OMIT,
        label_stream_navigation_disabled_at: typing.Optional[dt.datetime] = OMIT,
        organization: typing.Optional[int] = OMIT,
        read_only_quick_view_enabled_at: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DefaultRole:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Update the default role for members of a specific organization.

        Parameters
        ----------
        id : int

        annotator_reviewer_firewall_enabled_at : typing.Optional[dt.datetime]
            Set to current time to restrict data sharing between annotators and reviewers in the label stream, review stream, and notifications (which will be disabled). In these settings, information about annotator and reviewer identity is suppressed in the UI.

        custom_scripts_enabled_at : typing.Optional[dt.datetime]
            Set to current time to enable custom scripts (Plugins) for this organization. Can only be enabled if no organization members are active members of any other organizations; otherwise an error will be raised. If this occurs, contact the LEAP team for assistance with enabling custom scripts (Plugins).

        default_role : typing.Optional[Role9E7Enum]
            Default membership role for invited users

            * `OW` - Owner
            * `AD` - Administrator
            * `MA` - Manager
            * `RE` - Reviewer
            * `AN` - Annotator
            * `DI` - Deactivated
            * `NO` - Not Activated

        email_notification_settings : typing.Optional[typing.Any]
            Email notification settings for this organization. Controls which email notifications users can receive. Structure: {"notifications_allowed": {"notification_type": bool}}

        embed_domains : typing.Optional[typing.Any]
            List of objects: {"domain": "example.com"}. Used for CSP header on /embed routes.

        embed_settings : typing.Optional[typing.Any]
            Embed settings for this organization

        external_id : typing.Optional[str]
            External ID to uniquely identify this organization

        extra_data_on_activity_logs : typing.Optional[bool]

        label_stream_navigation_disabled_at : typing.Optional[dt.datetime]
            Set to current time to disable the label stream navigation for this organization. This will prevent users from going back in the label stream to view previous labels.

        organization : typing.Optional[int]
            A unique integer value identifying this organization.

        read_only_quick_view_enabled_at : typing.Optional[dt.datetime]
            Set to current time to prevent creating or editing annotations in quick view.

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

        Returns
        -------
        DefaultRole


        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.organizations.update_default_role(
                id=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_default_role(
            id,
            annotator_reviewer_firewall_enabled_at=annotator_reviewer_firewall_enabled_at,
            custom_scripts_enabled_at=custom_scripts_enabled_at,
            default_role=default_role,
            email_notification_settings=email_notification_settings,
            embed_domains=embed_domains,
            embed_settings=embed_settings,
            external_id=external_id,
            extra_data_on_activity_logs=extra_data_on_activity_logs,
            label_stream_navigation_disabled_at=label_stream_navigation_disabled_at,
            organization=organization,
            read_only_quick_view_enabled_at=read_only_quick_view_enabled_at,
            request_options=request_options,
        )
        return _response.data

    @property
    def invites(self):
        if self._invites is None:
            from .invites.client import AsyncInvitesClient  # noqa: E402

            self._invites = AsyncInvitesClient(client_wrapper=self._client_wrapper)
        return self._invites

    @property
    def member_tags(self):
        if self._member_tags is None:
            from .member_tags.client import AsyncMemberTagsClient  # noqa: E402

            self._member_tags = AsyncMemberTagsClient(client_wrapper=self._client_wrapper)
        return self._member_tags

    @property
    def members(self):
        if self._members is None:
            from .members.client import AsyncMembersClient  # noqa: E402

            self._members = AsyncMembersClient(client_wrapper=self._client_wrapper)
        return self._members

    @property
    def permissions(self):
        if self._permissions is None:
            from .permissions.client import AsyncPermissionsClient  # noqa: E402

            self._permissions = AsyncPermissionsClient(client_wrapper=self._client_wrapper)
        return self._permissions
