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

from __future__ import annotations

from dataclasses import dataclass
from typing import cast
from typing import Any, Dict, Literal, Union
from workos._types import _raise_deserialize_error

from .access_token_agent_registration_credential_issued_data_detail import (
    AccessTokenAgentRegistrationCredentialIssuedDataDetail,
)
from .agent_registration_credential_issued_data_detail import (
    AgentRegistrationCredentialIssuedDataDetail,
)


@dataclass(slots=True)
class AgentRegistrationCredentialIssuedData:
    """The event payload."""

    object: Literal["agent_registration_credential"]
    """Distinguishes the agent registration credential object."""
    id: str
    """Unique identifier of the agent registration credential."""
    agent_registration_id: str
    """The ID of the agent registration."""
    detail: Union[
        "AgentRegistrationCredentialIssuedDataDetail",
        "AccessTokenAgentRegistrationCredentialIssuedDataDetail",
    ]
    """Details of the issued credential."""
    created_at: str
    """The timestamp when the credential was issued."""
    updated_at: str
    """The timestamp when the credential was last updated."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "AgentRegistrationCredentialIssuedData":
        """Deserialize from a dictionary."""
        try:
            _detail_raw = data["detail"]
            _detail_data = cast(Dict[str, Any], _detail_raw)
            _detail_disc = cast(str, _detail_data.get("kind"))
            _detail_disc_map: Dict[str, Any] = {
                "api_key": AgentRegistrationCredentialIssuedDataDetail,
                "access_token": AccessTokenAgentRegistrationCredentialIssuedDataDetail,
            }
            _detail_cls = _detail_disc_map.get(_detail_disc)
            if _detail_cls is None:
                raise ValueError(
                    f"Unknown discriminator 'kind' for AgentRegistrationCredentialIssuedData.detail: {_detail_disc!r}. "
                    f"Expected one of {sorted(_detail_disc_map)}."
                )
            return cls(
                object=data.get("object", "agent_registration_credential"),
                id=data["id"],
                agent_registration_id=data["agent_registration_id"],
                detail=_detail_cls.from_dict(_detail_data),
                created_at=data["created_at"],
                updated_at=data["updated_at"],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("AgentRegistrationCredentialIssuedData", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["object"] = self.object
        result["id"] = self.id
        result["agent_registration_id"] = self.agent_registration_id
        result["detail"] = self.detail.to_dict()
        result["created_at"] = self.created_at
        result["updated_at"] = self.updated_at
        return result
