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

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from typing import Any, Dict, Optional
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime


@dataclass(slots=True)
class AgentCredentialValidation:
    """Agent Credential Validation model."""

    valid: bool
    """Whether the presented credential is valid."""
    registration_id: Optional[str]
    """Identifier of the agent registration the credential belongs to, or `null` when the credential is invalid."""
    expires_at: Optional[datetime]
    """The timestamp when the credential expires, or `null` when the credential is invalid."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AgentCredentialValidation":
        """Deserialize from a dictionary."""
        try:
            return cls(
                valid=data["valid"],
                registration_id=data["registration_id"],
                expires_at=_parse_datetime(_v_expires_at)
                if (_v_expires_at := data["expires_at"]) is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AgentCredentialValidation", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["valid"] = self.valid
        if self.registration_id is not None:
            result["registration_id"] = self.registration_id
        else:
            result["registration_id"] = None
        if self.expires_at is not None:
            result["expires_at"] = _format_datetime(self.expires_at)
        else:
            result["expires_at"] = None
        return result
