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

from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Literal

from workos._types import _raise_deserialize_error


@dataclass(slots=True)
class TokenQuery:
    """Token Query model."""

    client_id: str
    """The client ID of the WorkOS environment."""
    client_secret: str
    """The client secret of the WorkOS environment."""
    code: str
    """The authorization code received from the authorization callback."""
    grant_type: Literal["authorization_code"]
    """The grant type for the token request."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> TokenQuery:
        """Deserialize from a dictionary."""
        try:
            return cls(
                client_id=data["client_id"],
                client_secret=data["client_secret"],
                code=data["code"],
                grant_type=data.get("grant_type", "authorization_code"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("TokenQuery", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["client_id"] = self.client_id
        result["client_secret"] = self.client_secret
        result["code"] = self.code
        result["grant_type"] = self.grant_type
        return result
