# 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.assign_role_member_response import AssignRoleMemberResponse
from ..types.capability_metadata_response import CapabilityMetadataResponse
from ..types.effective_permissions_response import EffectivePermissionsResponse
from ..types.role_members_list_response import RoleMembersListResponse
from ..types.role_response import RoleResponse
from ..types.role_template_response import RoleTemplateResponse
from .raw_client import AsyncRawRolesClient, RawRolesClient

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


class RolesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawRolesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawRolesClient
        """
        return self._raw_client

    def create_custom_role(
        self,
        organization_id: str,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        capabilities: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RoleResponse:
        """
        Create a custom role for the organization.

        Parameters
        ----------
        organization_id : str

        name : str

        description : typing.Optional[str]

        capabilities : typing.Optional[typing.Sequence[str]]

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

        Returns
        -------
        RoleResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.roles.create_custom_role(
            organization_id="organization_id",
            name="name",
        )
        """
        _response = self._raw_client.create_custom_role(
            organization_id,
            name=name,
            description=description,
            capabilities=capabilities,
            request_options=request_options,
        )
        return _response.data

    def list_capabilities(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[CapabilityMetadataResponse]:
        """
        List all available capabilities with metadata.

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

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

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.roles.list_capabilities()
        """
        _response = self._raw_client.list_capabilities(request_options=request_options)
        return _response.data

    def list_role_templates(
        self, organization_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[RoleTemplateResponse]:
        """
        List available role templates for creating custom roles.

        Parameters
        ----------
        organization_id : str

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

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

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.roles.list_role_templates(
            organization_id="organization_id",
        )
        """
        _response = self._raw_client.list_role_templates(organization_id, request_options=request_options)
        return _response.data

    def get_role(
        self, organization_id: str, role_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> RoleResponse:
        """
        Get a single role by ID.

        Parameters
        ----------
        organization_id : str

        role_id : str

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

        Returns
        -------
        RoleResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.roles.get_role(
            organization_id="organization_id",
            role_id="role_id",
        )
        """
        _response = self._raw_client.get_role(organization_id, role_id, request_options=request_options)
        return _response.data

    def delete_custom_role(
        self, organization_id: str, role_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete a custom role. System roles cannot be deleted.

        Parameters
        ----------
        organization_id : str

        role_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.roles.delete_custom_role(
            organization_id="organization_id",
            role_id="role_id",
        )
        """
        _response = self._raw_client.delete_custom_role(organization_id, role_id, request_options=request_options)
        return _response.data

    def update_custom_role(
        self,
        organization_id: str,
        role_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        capabilities: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RoleResponse:
        """
        Update a custom role's name, description, or capabilities.

        Parameters
        ----------
        organization_id : str

        role_id : str

        name : typing.Optional[str]

        description : typing.Optional[str]

        capabilities : typing.Optional[typing.Sequence[str]]

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

        Returns
        -------
        RoleResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.roles.update_custom_role(
            organization_id="organization_id",
            role_id="role_id",
        )
        """
        _response = self._raw_client.update_custom_role(
            organization_id,
            role_id,
            name=name,
            description=description,
            capabilities=capabilities,
            request_options=request_options,
        )
        return _response.data

    def list_role_members(
        self,
        organization_id: str,
        role_id: str,
        *,
        skip: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RoleMembersListResponse:
        """
        List all users assigned to a specific role.

        Parameters
        ----------
        organization_id : str

        role_id : str

        skip : typing.Optional[int]

        limit : typing.Optional[int]

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

        Returns
        -------
        RoleMembersListResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.roles.list_role_members(
            organization_id="organization_id",
            role_id="role_id",
        )
        """
        _response = self._raw_client.list_role_members(
            organization_id, role_id, skip=skip, limit=limit, request_options=request_options
        )
        return _response.data

    def assign_role_member(
        self,
        organization_id: str,
        role_id: str,
        *,
        user_id: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AssignRoleMemberResponse:
        """
        Assign a user to a role.

        Parameters
        ----------
        organization_id : str

        role_id : str

        user_id : str

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

        Returns
        -------
        AssignRoleMemberResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.roles.assign_role_member(
            organization_id="organization_id",
            role_id="role_id",
            user_id="user_id",
        )
        """
        _response = self._raw_client.assign_role_member(
            organization_id, role_id, user_id=user_id, request_options=request_options
        )
        return _response.data

    def remove_role_member(
        self,
        organization_id: str,
        role_id: str,
        user_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Remove a user from a role.

        Parameters
        ----------
        organization_id : str

        role_id : str

        user_id : str
            User ID to remove from role

        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.roles.remove_role_member(
            organization_id="organization_id",
            role_id="role_id",
            user_id="user_id",
        )
        """
        _response = self._raw_client.remove_role_member(
            organization_id, role_id, user_id, request_options=request_options
        )
        return _response.data

    def get_effective_permissions(
        self, organization_id: str, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> EffectivePermissionsResponse:
        """
        Get resolved effective permissions for a user in an organization.

        Parameters
        ----------
        organization_id : str

        user_id : str

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

        Returns
        -------
        EffectivePermissionsResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.roles.get_effective_permissions(
            organization_id="organization_id",
            user_id="user_id",
        )
        """
        _response = self._raw_client.get_effective_permissions(
            organization_id, user_id, request_options=request_options
        )
        return _response.data


class AsyncRolesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawRolesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawRolesClient
        """
        return self._raw_client

    async def create_custom_role(
        self,
        organization_id: str,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        capabilities: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RoleResponse:
        """
        Create a custom role for the organization.

        Parameters
        ----------
        organization_id : str

        name : str

        description : typing.Optional[str]

        capabilities : typing.Optional[typing.Sequence[str]]

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

        Returns
        -------
        RoleResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

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


        async def main() -> None:
            await client.roles.create_custom_role(
                organization_id="organization_id",
                name="name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_custom_role(
            organization_id,
            name=name,
            description=description,
            capabilities=capabilities,
            request_options=request_options,
        )
        return _response.data

    async def list_capabilities(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[CapabilityMetadataResponse]:
        """
        List all available capabilities with metadata.

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

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

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

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


        async def main() -> None:
            await client.roles.list_capabilities()


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

    async def list_role_templates(
        self, organization_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[RoleTemplateResponse]:
        """
        List available role templates for creating custom roles.

        Parameters
        ----------
        organization_id : str

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

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

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

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


        async def main() -> None:
            await client.roles.list_role_templates(
                organization_id="organization_id",
            )


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

    async def get_role(
        self, organization_id: str, role_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> RoleResponse:
        """
        Get a single role by ID.

        Parameters
        ----------
        organization_id : str

        role_id : str

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

        Returns
        -------
        RoleResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

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


        async def main() -> None:
            await client.roles.get_role(
                organization_id="organization_id",
                role_id="role_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_role(organization_id, role_id, request_options=request_options)
        return _response.data

    async def delete_custom_role(
        self, organization_id: str, role_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete a custom role. System roles cannot be deleted.

        Parameters
        ----------
        organization_id : str

        role_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.roles.delete_custom_role(
                organization_id="organization_id",
                role_id="role_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_custom_role(organization_id, role_id, request_options=request_options)
        return _response.data

    async def update_custom_role(
        self,
        organization_id: str,
        role_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        capabilities: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RoleResponse:
        """
        Update a custom role's name, description, or capabilities.

        Parameters
        ----------
        organization_id : str

        role_id : str

        name : typing.Optional[str]

        description : typing.Optional[str]

        capabilities : typing.Optional[typing.Sequence[str]]

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

        Returns
        -------
        RoleResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

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


        async def main() -> None:
            await client.roles.update_custom_role(
                organization_id="organization_id",
                role_id="role_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_custom_role(
            organization_id,
            role_id,
            name=name,
            description=description,
            capabilities=capabilities,
            request_options=request_options,
        )
        return _response.data

    async def list_role_members(
        self,
        organization_id: str,
        role_id: str,
        *,
        skip: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RoleMembersListResponse:
        """
        List all users assigned to a specific role.

        Parameters
        ----------
        organization_id : str

        role_id : str

        skip : typing.Optional[int]

        limit : typing.Optional[int]

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

        Returns
        -------
        RoleMembersListResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

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


        async def main() -> None:
            await client.roles.list_role_members(
                organization_id="organization_id",
                role_id="role_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_role_members(
            organization_id, role_id, skip=skip, limit=limit, request_options=request_options
        )
        return _response.data

    async def assign_role_member(
        self,
        organization_id: str,
        role_id: str,
        *,
        user_id: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AssignRoleMemberResponse:
        """
        Assign a user to a role.

        Parameters
        ----------
        organization_id : str

        role_id : str

        user_id : str

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

        Returns
        -------
        AssignRoleMemberResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

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


        async def main() -> None:
            await client.roles.assign_role_member(
                organization_id="organization_id",
                role_id="role_id",
                user_id="user_id",
            )


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

    async def remove_role_member(
        self,
        organization_id: str,
        role_id: str,
        user_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Remove a user from a role.

        Parameters
        ----------
        organization_id : str

        role_id : str

        user_id : str
            User ID to remove from role

        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.roles.remove_role_member(
                organization_id="organization_id",
                role_id="role_id",
                user_id="user_id",
            )


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

    async def get_effective_permissions(
        self, organization_id: str, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> EffectivePermissionsResponse:
        """
        Get resolved effective permissions for a user in an organization.

        Parameters
        ----------
        organization_id : str

        user_id : str

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

        Returns
        -------
        EffectivePermissionsResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

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


        async def main() -> None:
            await client.roles.get_effective_permissions(
                organization_id="organization_id",
                user_id="user_id",
            )


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