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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.pagination import AsyncPager, SyncPager
from ..core.request_options import RequestOptions
from ..types.api_role import ApiRole
from ..types.corpus_key import CorpusKey
from ..types.user import User
from .raw_client import AsyncRawUsersClient, RawUsersClient
from .types.users_create_response import UsersCreateResponse
from .types.users_reset_password_response import UsersResetPasswordResponse

# 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(
        self,
        *,
        limit: typing.Optional[int] = None,
        page_key: typing.Optional[str] = None,
        corpus_key: typing.Optional[CorpusKey] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[User]:
        """
        Lists all users in the account.

        Parameters
        ----------
        limit : typing.Optional[int]
            The maximum number of users to return at one time.

        page_key : typing.Optional[str]
            Used to retrieve the next page of users after the limit has been reached.

        corpus_key : typing.Optional[CorpusKey]
            Filter users by access to this corpus.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        SyncPager[User]
            List of users.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        response = client.users.list(corpus_key='my-corpus', )
        for item in response:
            yield item
        # alternatively, you can paginate page-by-page
        for page in response.iter_pages():
            yield page
        """
        response = self._raw_client.list(
            limit=limit,
            page_key=page_key,
            corpus_key=corpus_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    def create(
        self,
        *,
        email: str,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        username: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        api_roles: typing.Optional[typing.Sequence[ApiRole]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UsersCreateResponse:
        """
        Create a user for the current customer account.

        Parameters
        ----------
        email : str
            The email address for the user.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        username : typing.Optional[str]
            The username for the user. The value defaults to the email.

        description : typing.Optional[str]
            The description of the user.

        api_roles : typing.Optional[typing.Sequence[ApiRole]]
            The role names assigned to the user.

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

        Returns
        -------
        UsersCreateResponse
            The created user.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.users.create(email='email', )
        """
        response = self._raw_client.create(
            email=email,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            username=username,
            description=description,
            api_roles=api_roles,
            request_options=request_options,
        )
        return response.data

    def get(
        self,
        username: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> User:
        """
        Get a user and view details like the email, username, and associated roles.

        Parameters
        ----------
        username : str
            Specifies the user ID that to retrieve.
            Note that the username must be percent encoded.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        User
            A user.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.users.get(username='username', )
        """
        response = self._raw_client.get(
            username,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    def delete(
        self,
        username: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Delete a user from the account.

        Parameters
        ----------
        username : str
            Specifies the user ID to delete.
            Note that the username must be percent encoded.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        None

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.users.delete(username='username', )
        """
        response = self._raw_client.delete(
            username,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    def update(
        self,
        username: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        enabled: typing.Optional[bool] = OMIT,
        api_roles: typing.Optional[typing.Sequence[ApiRole]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> User:
        """
        Update details about a user such as role names.

        Parameters
        ----------
        username : str
            Specifies the user ID to update.
            Note that the username must be percent encoded.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        enabled : typing.Optional[bool]
            Indicates whether to enable or disable the user.

        api_roles : typing.Optional[typing.Sequence[ApiRole]]
            The new role names of the user.

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

        Returns
        -------
        User
            New user after modification.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.users.update(username='username', )
        """
        response = self._raw_client.update(
            username,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            enabled=enabled,
            api_roles=api_roles,
            request_options=request_options,
        )
        return response.data

    def reset_password(
        self,
        username: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UsersResetPasswordResponse:
        """
        Reset the password for a user.

        Parameters
        ----------
        username : str
            Specifies the user ID to update.
            Note that the username must be percent encoded and URI safe.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        UsersResetPasswordResponse
            User was sent the password reset email.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.users.reset_password(username='username', )
        """
        response = self._raw_client.reset_password(
            username,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            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(
        self,
        *,
        limit: typing.Optional[int] = None,
        page_key: typing.Optional[str] = None,
        corpus_key: typing.Optional[CorpusKey] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[User]:
        """
        Lists all users in the account.

        Parameters
        ----------
        limit : typing.Optional[int]
            The maximum number of users to return at one time.

        page_key : typing.Optional[str]
            Used to retrieve the next page of users after the limit has been reached.

        corpus_key : typing.Optional[CorpusKey]
            Filter users by access to this corpus.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        AsyncPager[User]
            List of users.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            response = await client.users.list(corpus_key='my-corpus', )
            async for item in response:
                yield item

            # alternatively, you can paginate page-by-page
            async for page in response.iter_pages():
                yield page
        asyncio.run(main())
        """
        response = await self._raw_client.list(
            limit=limit,
            page_key=page_key,
            corpus_key=corpus_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    async def create(
        self,
        *,
        email: str,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        username: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        api_roles: typing.Optional[typing.Sequence[ApiRole]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UsersCreateResponse:
        """
        Create a user for the current customer account.

        Parameters
        ----------
        email : str
            The email address for the user.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        username : typing.Optional[str]
            The username for the user. The value defaults to the email.

        description : typing.Optional[str]
            The description of the user.

        api_roles : typing.Optional[typing.Sequence[ApiRole]]
            The role names assigned to the user.

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

        Returns
        -------
        UsersCreateResponse
            The created user.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.users.create(email='email', )
        asyncio.run(main())
        """
        response = await self._raw_client.create(
            email=email,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            username=username,
            description=description,
            api_roles=api_roles,
            request_options=request_options,
        )
        return response.data

    async def get(
        self,
        username: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> User:
        """
        Get a user and view details like the email, username, and associated roles.

        Parameters
        ----------
        username : str
            Specifies the user ID that to retrieve.
            Note that the username must be percent encoded.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        User
            A user.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.users.get(username='username', )
        asyncio.run(main())
        """
        response = await self._raw_client.get(
            username,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    async def delete(
        self,
        username: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Delete a user from the account.

        Parameters
        ----------
        username : str
            Specifies the user ID to delete.
            Note that the username must be percent encoded.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        None

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.users.delete(username='username', )
        asyncio.run(main())
        """
        response = await self._raw_client.delete(
            username,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    async def update(
        self,
        username: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        enabled: typing.Optional[bool] = OMIT,
        api_roles: typing.Optional[typing.Sequence[ApiRole]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> User:
        """
        Update details about a user such as role names.

        Parameters
        ----------
        username : str
            Specifies the user ID to update.
            Note that the username must be percent encoded.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        enabled : typing.Optional[bool]
            Indicates whether to enable or disable the user.

        api_roles : typing.Optional[typing.Sequence[ApiRole]]
            The new role names of the user.

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

        Returns
        -------
        User
            New user after modification.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.users.update(username='username', )
        asyncio.run(main())
        """
        response = await self._raw_client.update(
            username,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            enabled=enabled,
            api_roles=api_roles,
            request_options=request_options,
        )
        return response.data

    async def reset_password(
        self,
        username: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UsersResetPasswordResponse:
        """
        Reset the password for a user.

        Parameters
        ----------
        username : str
            Specifies the user ID to update.
            Note that the username must be percent encoded and URI safe.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        UsersResetPasswordResponse
            User was sent the password reset email.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.users.reset_password(username='username', )
        asyncio.run(main())
        """
        response = await self._raw_client.reset_password(
            username,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data
