# 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_user_request_roles import CreateUserRequestRoles
from ..types.list_user_roles_response import ListUserRolesResponse
from ..types.list_users_response import ListUsersResponse
from ..types.user_response import UserResponse
from .raw_client import AsyncRawUsersClient, RawUsersClient
from .types.create_user_request_auth_type import CreateUserRequestAuthType
from .types.update_user_request_auth_type import UpdateUserRequestAuthType

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


class UsersClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawUsersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawUsersClient
        """
        return self._raw_client

    def list_user_roles(
        self,
        *,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListUserRolesResponse:
        """
        Returns a list of all user roles in an organization.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Read Users** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        limit : typing.Optional[int]
            The limit for how many objects will be in the response. Default and max for this value is 512 objects.

        after : typing.Optional[str]
            If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results.

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

        Returns
        -------
        ListUserRolesResponse
            List all user roles.

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.users.list_user_roles()
        """
        _response = self._raw_client.list_user_roles(limit=limit, after=after, request_options=request_options)
        return _response.data

    def list_users(
        self,
        *,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListUsersResponse:
        """
        Returns a list of all users in an organization. Users that have expired access will not be returned.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Read Users** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        limit : typing.Optional[int]
            The limit for how many objects will be in the response. Default and max for this value is 512 objects.

        after : typing.Optional[str]
            If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results.

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

        Returns
        -------
        ListUsersResponse
            List all users.

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.users.list_users()
        """
        _response = self._raw_client.list_users(limit=limit, after=after, request_options=request_options)
        return _response.data

    def create_user(
        self,
        *,
        auth_type: CreateUserRequestAuthType,
        email: str,
        name: str,
        roles: typing.Sequence[CreateUserRequestRoles],
        expire_at: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UserResponse:
        """
        Add a user to the organization.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Write Users** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        auth_type : CreateUserRequestAuthType
            The authentication type the user uses to authenticate. To use SAML this organization must have a configured SAML integration. Valid values: `default`, `saml`.

        email : str
            The email address of this user.

        name : str
            The first and last name of the user.

        roles : typing.Sequence[CreateUserRequestRoles]
            The list of roles that applies to this user. A user may have "organizational" roles, which apply to the user at the organizational level, and "tag-specific" roles, which apply to the user for a given tag.

        expire_at : typing.Optional[str]
            For users with temporary access, this is the expiration datetime in RFC3339 format

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

        Returns
        -------
        UserResponse
            Newly created user object with ID.

        Examples
        --------
        from samsara import CreateUserRequestRoles, Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.users.create_user(
            auth_type="default",
            email="user@company.com",
            name="Bob Smith",
            roles=[
                CreateUserRequestRoles(
                    role_id="8a9371af-82d1-4158-bf91-4ecc8d3a114c",
                )
            ],
        )
        """
        _response = self._raw_client.create_user(
            auth_type=auth_type,
            email=email,
            name=name,
            roles=roles,
            expire_at=expire_at,
            request_options=request_options,
        )
        return _response.data

    def get_user(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> UserResponse:
        """
        Get a specific user's information. Users that have expired access will not be returned.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Read Users** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        id : str
            Unique identifier for the user.

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

        Returns
        -------
        UserResponse
            Returns the specified user.

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.users.get_user(
            id="id",
        )
        """
        _response = self._raw_client.get_user(id, request_options=request_options)
        return _response.data

    def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete the given user.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Write Users** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        id : str
            Unique identifier for the user.

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

        Returns
        -------
        None

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.users.delete(
            id="id",
        )
        """
        _response = self._raw_client.delete(id, request_options=request_options)
        return _response.data

    def update_user(
        self,
        id: str,
        *,
        auth_type: typing.Optional[UpdateUserRequestAuthType] = OMIT,
        expire_at: typing.Optional[str] = OMIT,
        name: typing.Optional[str] = OMIT,
        roles: typing.Optional[typing.Sequence[CreateUserRequestRoles]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UserResponse:
        """
        Update a specific user's information.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Write Users** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        id : str
            Unique identifier for the user.

        auth_type : typing.Optional[UpdateUserRequestAuthType]
            The authentication type the user uses to authenticate. To use SAML this organization must have a configured SAML integration. Valid values: `default`, `saml`.

        expire_at : typing.Optional[str]
            For users with temporary access, this is the expiration datetime in RFC3339 format

        name : typing.Optional[str]
            The first and last name of the user.

        roles : typing.Optional[typing.Sequence[CreateUserRequestRoles]]
            The list of roles that applies to this user. A user may have "organizational" roles, which apply to the user at the organizational level, and "tag-specific" roles, which apply to the user for a given tag.

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

        Returns
        -------
        UserResponse
            Updated user object with ID.

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.users.update_user(
            id="id",
        )
        """
        _response = self._raw_client.update_user(
            id, auth_type=auth_type, expire_at=expire_at, name=name, roles=roles, request_options=request_options
        )
        return _response.data


class AsyncUsersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawUsersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawUsersClient
        """
        return self._raw_client

    async def list_user_roles(
        self,
        *,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListUserRolesResponse:
        """
        Returns a list of all user roles in an organization.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Read Users** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        limit : typing.Optional[int]
            The limit for how many objects will be in the response. Default and max for this value is 512 objects.

        after : typing.Optional[str]
            If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results.

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

        Returns
        -------
        ListUserRolesResponse
            List all user roles.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.users.list_user_roles()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_user_roles(limit=limit, after=after, request_options=request_options)
        return _response.data

    async def list_users(
        self,
        *,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListUsersResponse:
        """
        Returns a list of all users in an organization. Users that have expired access will not be returned.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Read Users** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        limit : typing.Optional[int]
            The limit for how many objects will be in the response. Default and max for this value is 512 objects.

        after : typing.Optional[str]
            If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results.

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

        Returns
        -------
        ListUsersResponse
            List all users.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.users.list_users()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_users(limit=limit, after=after, request_options=request_options)
        return _response.data

    async def create_user(
        self,
        *,
        auth_type: CreateUserRequestAuthType,
        email: str,
        name: str,
        roles: typing.Sequence[CreateUserRequestRoles],
        expire_at: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UserResponse:
        """
        Add a user to the organization.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Write Users** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        auth_type : CreateUserRequestAuthType
            The authentication type the user uses to authenticate. To use SAML this organization must have a configured SAML integration. Valid values: `default`, `saml`.

        email : str
            The email address of this user.

        name : str
            The first and last name of the user.

        roles : typing.Sequence[CreateUserRequestRoles]
            The list of roles that applies to this user. A user may have "organizational" roles, which apply to the user at the organizational level, and "tag-specific" roles, which apply to the user for a given tag.

        expire_at : typing.Optional[str]
            For users with temporary access, this is the expiration datetime in RFC3339 format

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

        Returns
        -------
        UserResponse
            Newly created user object with ID.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara, CreateUserRequestRoles

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.users.create_user(
                auth_type="default",
                email="user@company.com",
                name="Bob Smith",
                roles=[
                    CreateUserRequestRoles(
                        role_id="8a9371af-82d1-4158-bf91-4ecc8d3a114c",
                    )
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_user(
            auth_type=auth_type,
            email=email,
            name=name,
            roles=roles,
            expire_at=expire_at,
            request_options=request_options,
        )
        return _response.data

    async def get_user(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> UserResponse:
        """
        Get a specific user's information. Users that have expired access will not be returned.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Read Users** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        id : str
            Unique identifier for the user.

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

        Returns
        -------
        UserResponse
            Returns the specified user.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.users.get_user(
                id="id",
            )


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

    async def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete the given user.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Write Users** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        id : str
            Unique identifier for the user.

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.users.delete(
                id="id",
            )


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

    async def update_user(
        self,
        id: str,
        *,
        auth_type: typing.Optional[UpdateUserRequestAuthType] = OMIT,
        expire_at: typing.Optional[str] = OMIT,
        name: typing.Optional[str] = OMIT,
        roles: typing.Optional[typing.Sequence[CreateUserRequestRoles]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UserResponse:
        """
        Update a specific user's information.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Write Users** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        id : str
            Unique identifier for the user.

        auth_type : typing.Optional[UpdateUserRequestAuthType]
            The authentication type the user uses to authenticate. To use SAML this organization must have a configured SAML integration. Valid values: `default`, `saml`.

        expire_at : typing.Optional[str]
            For users with temporary access, this is the expiration datetime in RFC3339 format

        name : typing.Optional[str]
            The first and last name of the user.

        roles : typing.Optional[typing.Sequence[CreateUserRequestRoles]]
            The list of roles that applies to this user. A user may have "organizational" roles, which apply to the user at the organizational level, and "tag-specific" roles, which apply to the user for a given tag.

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

        Returns
        -------
        UserResponse
            Updated user object with ID.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.users.update_user(
                id="id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_user(
            id, auth_type=auth_type, expire_at=expire_at, name=name, roles=roles, request_options=request_options
        )
        return _response.data
