# This file is auto-generated by oagen. Do not edit.

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, Optional

if TYPE_CHECKING:
    from .._client import AsyncWorkOSClient, WorkOSClient

from .._types import RequestOptions
from .models import ClientApiTokenResponse


class ClientApi:
    """Client Api API resources."""

    def __init__(self, client: "WorkOSClient") -> None:
        self._client = client

    def create_token(
        self,
        *,
        organization_id: str,
        user_id: str,
        request_options: Optional[RequestOptions] = None,
    ) -> ClientApiTokenResponse:
        """Generate a Client API token

        Generate a short-lived, session-bound token for the Client GraphQL API, scoped to an organization and user.

        Args:
            organization_id: The ID of the organization to scope the Client API token to.
            user_id: The ID of the user to issue the Client API token for.
            request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.

        Returns:
            ClientApiTokenResponse

        Raises:
            BadRequestError: If the request is malformed (400).
            NotFoundError: If the resource is not found (404).
            UnprocessableEntityError: If the request data is unprocessable (422).
            AuthenticationError: If the API key is invalid (401).
            RateLimitExceededError: If rate limited (429).
            ServerError: If the server returns a 5xx error.
        """
        body: Dict[str, Any] = {
            "organization_id": organization_id,
            "user_id": user_id,
        }
        return self._client.request(
            method="post",
            path=("client", "token"),
            body=body,
            model=ClientApiTokenResponse,
            request_options=request_options,
        )


class AsyncClientApi:
    """Client Api API resources (async)."""

    def __init__(self, client: "AsyncWorkOSClient") -> None:
        self._client = client

    async def create_token(
        self,
        *,
        organization_id: str,
        user_id: str,
        request_options: Optional[RequestOptions] = None,
    ) -> ClientApiTokenResponse:
        """Generate a Client API token

        Generate a short-lived, session-bound token for the Client GraphQL API, scoped to an organization and user.

        Args:
            organization_id: The ID of the organization to scope the Client API token to.
            user_id: The ID of the user to issue the Client API token for.
            request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.

        Returns:
            ClientApiTokenResponse

        Raises:
            BadRequestError: If the request is malformed (400).
            NotFoundError: If the resource is not found (404).
            UnprocessableEntityError: If the request data is unprocessable (422).
            AuthenticationError: If the API key is invalid (401).
            RateLimitExceededError: If rate limited (429).
            ServerError: If the server returns a 5xx error.
        """
        body: Dict[str, Any] = {
            "organization_id": organization_id,
            "user_id": user_id,
        }
        return await self._client.request(
            method="post",
            path=("client", "token"),
            body=body,
            model=ClientApiTokenResponse,
            request_options=request_options,
        )
