# 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 AuthorizationCodeSessionAuthenticateRequest:
    """Authorization Code Session Authenticate Request model."""

    client_id: str
    """The client ID of the application."""
    grant_type: Literal["authorization_code"]
    code: str
    """The authorization code received from the redirect."""
    client_secret: str | None = None
    """The client secret of the application. May be omitted by public clients that authenticate through other means, such as a PKCE `code_verifier`."""
    code_verifier: str | None = None
    """The PKCE code verifier used to derive the code challenge passed to the authorization URL."""
    invitation_token: str | None = None
    """An invitation token to accept during authentication."""
    ip_address: str | None = None
    """The IP address of the user's request."""
    device_id: str | None = None
    """A unique identifier for the device."""
    user_agent: str | None = None
    """The user agent string from the user's browser."""
    signals_id: str | None = None
    """An optional Radar signals ID to correlate client-side signals with this authentication attempt."""

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

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["client_id"] = self.client_id
        result["grant_type"] = self.grant_type
        result["code"] = self.code
        if self.client_secret is not None:
            result["client_secret"] = self.client_secret
        if self.code_verifier is not None:
            result["code_verifier"] = self.code_verifier
        if self.invitation_token is not None:
            result["invitation_token"] = self.invitation_token
        if self.ip_address is not None:
            result["ip_address"] = self.ip_address
        if self.device_id is not None:
            result["device_id"] = self.device_id
        if self.user_agent is not None:
            result["user_agent"] = self.user_agent
        if self.signals_id is not None:
            result["signals_id"] = self.signals_id
        return result
