# 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 AgentRegistrationAgentIdentity:
    """The agent identity associated with this registration."""

    id: str
    """Unique identifier of the agent identity."""
    userland_user_id: Optional[str]
    """Identifier of the AuthKit user the agent identity is bound to, or `null` when the agent is not associated with a user."""
    created_at: datetime
    """The timestamp when the agent identity was created."""
    updated_at: datetime
    """The timestamp when the agent identity was last updated."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AgentRegistrationAgentIdentity":
        """Deserialize from a dictionary."""
        try:
            return cls(
                id=data["id"],
                userland_user_id=data["userland_user_id"],
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AgentRegistrationAgentIdentity", e)

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