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

from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, Optional
from workos._types import _raise_deserialize_error
from workos.common.models.agent_admin_validate_credential_request_type import (
    AgentAdminValidateCredentialRequestType,
)


@dataclass(slots=True)
class AgentAdminValidateCredentialRequest:
    """Agent Admin Validate Credential Request model."""

    type: "AgentAdminValidateCredentialRequestType"
    """The kind of credential being validated — an agent API key or an agent access token."""
    credential: str
    """The credential value to validate: the API key value for `api_key`, or the access token (JWT) for `access_token`."""
    audience: Optional[str] = None
    """When provided, the access token's `aud` claim is verified against this value. Tokens issued for a different resource are rejected."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AgentAdminValidateCredentialRequest":
        """Deserialize from a dictionary."""
        try:
            return cls(
                type=AgentAdminValidateCredentialRequestType(data["type"]),
                credential=data["credential"],
                audience=data.get("audience"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AgentAdminValidateCredentialRequest", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["type"] = self.type.value if isinstance(self.type, Enum) else self.type
        result["credential"] = self.credential
        if self.audience is not None:
            result["audience"] = self.audience
        return result
