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

from __future__ import annotations

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

from .agent_registration_agent_identity import AgentRegistrationAgentIdentity
from .agent_registration_claim import AgentRegistrationClaim
from workos.common.models.agent_registration_kind import AgentRegistrationKind
from workos.common.models.agent_registration_status import AgentRegistrationStatus


@dataclass(slots=True)
class AgentRegistration:
    """Agent Registration model."""

    id: str
    """Unique identifier of the agent registration."""
    agent_identity: "AgentRegistrationAgentIdentity"
    """The agent identity associated with this registration."""
    organization_id: str
    """Identifier of the organization the agent is registered to."""
    status: "AgentRegistrationStatus"
    """The current verification status of the registration."""
    kind: "AgentRegistrationKind"
    """The kind of agent registration."""
    claim: Optional["AgentRegistrationClaim"]
    """The claim associated with this registration, or `null` if the registration has no claim."""
    created_at: datetime
    """The timestamp when the registration was created."""
    updated_at: datetime
    """The timestamp when the registration was last updated."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AgentRegistration":
        """Deserialize from a dictionary."""
        try:
            return cls(
                id=data["id"],
                agent_identity=AgentRegistrationAgentIdentity.from_dict(
                    cast(Dict[str, Any], data["agent_identity"])
                ),
                organization_id=data["organization_id"],
                status=AgentRegistrationStatus(data["status"]),
                kind=AgentRegistrationKind(data["kind"]),
                claim=AgentRegistrationClaim.from_dict(cast(Dict[str, Any], _v_claim))
                if (_v_claim := data["claim"]) is not None
                else None,
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AgentRegistration", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["id"] = self.id
        result["agent_identity"] = self.agent_identity.to_dict()
        result["organization_id"] = self.organization_id
        result["status"] = (
            self.status.value if isinstance(self.status, Enum) else self.status
        )
        result["kind"] = self.kind.value if isinstance(self.kind, Enum) else self.kind
        if self.claim is not None:
            result["claim"] = self.claim.to_dict()
        else:
            result["claim"] = None
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        return result
