# 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 Any, Dict, Literal, Optional
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime
from .invitation_accepted_data_state import InvitationAcceptedDataState


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

    object: Literal["invitation"]
    """Distinguishes the invitation object."""
    id: str
    """The unique ID of the invitation."""
    email: str
    """The email address of the recipient."""
    state: "InvitationAcceptedDataState"
    """The state of the invitation."""
    accepted_at: Optional[datetime]
    """The timestamp when the invitation was accepted, or null if not yet accepted."""
    revoked_at: Optional[datetime]
    """The timestamp when the invitation was revoked, or null if not revoked."""
    expires_at: datetime
    """The timestamp when the invitation expires."""
    organization_id: Optional[str]
    """The ID of the [organization](https://workos.com/docs/reference/organization) that the recipient will join."""
    inviter_user_id: Optional[str]
    """The ID of the user who invited the recipient, if provided."""
    accepted_user_id: Optional[str]
    """The ID of the user who accepted the invitation, once accepted."""
    role_slug: Optional[str]
    """Slug of the role the invitee will be assigned on acceptance. Reflects the current role on the invitee's organization membership. null when the invitation has no associated organization."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "InvitationAcceptedData":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "invitation"),
                id=data["id"],
                email=data["email"],
                state=InvitationAcceptedDataState(data["state"]),
                accepted_at=_parse_datetime(_v_accepted_at)
                if (_v_accepted_at := data["accepted_at"]) is not None
                else None,
                revoked_at=_parse_datetime(_v_revoked_at)
                if (_v_revoked_at := data["revoked_at"]) is not None
                else None,
                expires_at=_parse_datetime(data["expires_at"]),
                organization_id=data["organization_id"],
                inviter_user_id=data["inviter_user_id"],
                accepted_user_id=data["accepted_user_id"],
                role_slug=data["role_slug"],
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("InvitationAcceptedData", 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["email"] = self.email
        result["state"] = (
            self.state.value if isinstance(self.state, Enum) else self.state
        )
        if self.accepted_at is not None:
            result["accepted_at"] = _format_datetime(self.accepted_at)
        else:
            result["accepted_at"] = None
        if self.revoked_at is not None:
            result["revoked_at"] = _format_datetime(self.revoked_at)
        else:
            result["revoked_at"] = None
        result["expires_at"] = _format_datetime(self.expires_at)
        if self.organization_id is not None:
            result["organization_id"] = self.organization_id
        else:
            result["organization_id"] = None
        if self.inviter_user_id is not None:
            result["inviter_user_id"] = self.inviter_user_id
        else:
            result["inviter_user_id"] = None
        if self.accepted_user_id is not None:
            result["accepted_user_id"] = self.accepted_user_id
        else:
            result["accepted_user_id"] = None
        if self.role_slug is not None:
            result["role_slug"] = self.role_slug
        else:
            result["role_slug"] = None
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        return result
