# 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.access_level import AccessLevel
from ..types.access_right_list_response import AccessRightListResponse
from ..types.access_right_response import AccessRightResponse
from .raw_client import AsyncRawRuleAccessRightsClient, RawRuleAccessRightsClient

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


class RuleAccessRightsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawRuleAccessRightsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawRuleAccessRightsClient
        """
        return self._raw_client

    def list_access_rights(
        self, rule_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AccessRightListResponse:
        """
        Get all access rights for a rule. Only owners can view access rights.

        Parameters
        ----------
        rule_id : str

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

        Returns
        -------
        AccessRightListResponse
            Access rights retrieved successfully

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.rule_access_rights.list_access_rights(
            rule_id="rule_id",
        )
        """
        _response = self._raw_client.list_access_rights(rule_id, request_options=request_options)
        return _response.data

    def grant_access(
        self,
        rule_id: str,
        *,
        user_id: str,
        access_level: AccessLevel,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AccessRightResponse:
        """
        Grant access rights to a user for a rule. Only owners can grant access.

        Parameters
        ----------
        rule_id : str

        user_id : str
            User ID to grant access to

        access_level : AccessLevel
            Access level to grant

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

        Returns
        -------
        AccessRightResponse
            Access granted successfully

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.rule_access_rights.grant_access(
            rule_id="rule_id",
            user_id="usr_collaborator",
            access_level="owner",
        )
        """
        _response = self._raw_client.grant_access(
            rule_id, user_id=user_id, access_level=access_level, request_options=request_options
        )
        return _response.data

    def update_access_level(
        self,
        rule_id: str,
        user_id_: str,
        *,
        user_id: str,
        access_level: AccessLevel,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AccessRightResponse:
        """
        Update the access level for a user on a rule. Only owners can update access levels.

        Parameters
        ----------
        rule_id : str

        user_id_ : str

        user_id : str
            User ID to grant access to

        access_level : AccessLevel
            Access level to grant

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

        Returns
        -------
        AccessRightResponse
            Access level updated successfully

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.rule_access_rights.update_access_level(
            rule_id="rule_id",
            user_id_="user_id",
            user_id="usr_collaborator",
            access_level="owner",
        )
        """
        _response = self._raw_client.update_access_level(
            rule_id, user_id_, user_id=user_id, access_level=access_level, request_options=request_options
        )
        return _response.data

    def revoke_access(
        self, rule_id: str, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Revoke access rights from a user for a rule. Only owners can revoke access.

        Parameters
        ----------
        rule_id : str

        user_id : str

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

        Returns
        -------
        None

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.rule_access_rights.revoke_access(
            rule_id="rule_id",
            user_id="user_id",
        )
        """
        _response = self._raw_client.revoke_access(rule_id, user_id, request_options=request_options)
        return _response.data


class AsyncRuleAccessRightsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawRuleAccessRightsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawRuleAccessRightsClient
        """
        return self._raw_client

    async def list_access_rights(
        self, rule_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AccessRightListResponse:
        """
        Get all access rights for a rule. Only owners can view access rights.

        Parameters
        ----------
        rule_id : str

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

        Returns
        -------
        AccessRightListResponse
            Access rights retrieved successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.rule_access_rights.list_access_rights(
                rule_id="rule_id",
            )


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

    async def grant_access(
        self,
        rule_id: str,
        *,
        user_id: str,
        access_level: AccessLevel,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AccessRightResponse:
        """
        Grant access rights to a user for a rule. Only owners can grant access.

        Parameters
        ----------
        rule_id : str

        user_id : str
            User ID to grant access to

        access_level : AccessLevel
            Access level to grant

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

        Returns
        -------
        AccessRightResponse
            Access granted successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.rule_access_rights.grant_access(
                rule_id="rule_id",
                user_id="usr_collaborator",
                access_level="owner",
            )


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

    async def update_access_level(
        self,
        rule_id: str,
        user_id_: str,
        *,
        user_id: str,
        access_level: AccessLevel,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AccessRightResponse:
        """
        Update the access level for a user on a rule. Only owners can update access levels.

        Parameters
        ----------
        rule_id : str

        user_id_ : str

        user_id : str
            User ID to grant access to

        access_level : AccessLevel
            Access level to grant

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

        Returns
        -------
        AccessRightResponse
            Access level updated successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.rule_access_rights.update_access_level(
                rule_id="rule_id",
                user_id_="user_id",
                user_id="usr_collaborator",
                access_level="owner",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_access_level(
            rule_id, user_id_, user_id=user_id, access_level=access_level, request_options=request_options
        )
        return _response.data

    async def revoke_access(
        self, rule_id: str, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Revoke access rights from a user for a rule. Only owners can revoke access.

        Parameters
        ----------
        rule_id : str

        user_id : str

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.rule_access_rights.revoke_access(
                rule_id="rule_id",
                user_id="user_id",
            )


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