# 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, Optional
from workos._types import _raise_deserialize_error

from .agent_admin_link_claim_attempt_to_external_user_request_user import (
    AgentAdminLinkClaimAttemptToExternalUserRequestUser,
)


@dataclass(slots=True)
class AgentAdminLinkClaimAttemptToExternalUserRequest:
    """Agent Admin Link Claim Attempt To External User Request model."""

    type: Literal["link_external_user"]
    """The operation to perform on the claim attempt. Currently only `link_external_user` is supported."""
    claim_attempt_token: str
    """The token identifying the claim attempt."""
    user: "AgentAdminLinkClaimAttemptToExternalUserRequestUser"
    """The user to attach to the claim attempt, identified by email and external ID."""
    organization_id: Optional[str] = None
    """The organization to place the agent in. Required when the user belongs to more than one organization."""

    @classmethod
    def from_dict(
        cls, data: Dict[str, Any]
    ) -> "AgentAdminLinkClaimAttemptToExternalUserRequest":
        """Deserialize from a dictionary."""
        try:
            return cls(
                type=data.get("type", "link_external_user"),
                claim_attempt_token=data["claim_attempt_token"],
                user=AgentAdminLinkClaimAttemptToExternalUserRequestUser.from_dict(
                    cast(Dict[str, Any], data["user"])
                ),
                organization_id=data.get("organization_id"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error(
                "AgentAdminLinkClaimAttemptToExternalUserRequest", e
            )

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["type"] = self.type
        result["claim_attempt_token"] = self.claim_attempt_token
        result["user"] = self.user.to_dict()
        if self.organization_id is not None:
            result["organization_id"] = self.organization_id
        return result
