"""Record for out of band invitations."""
from typing import Any, Mapping, Union
from marshmallow import fields
from .....messaging.models.base_record import BaseExchangeRecord, BaseExchangeSchema
from .....messaging.valid import UUIDFour
from ..messages.invitation import InvitationMessage, InvitationMessageSchema
[docs]class InvitationRecord(BaseExchangeRecord):
"""Represents an out of band invitation record."""
RECORD_TYPE = "oob_invitation"
RECORD_ID_NAME = "invitation_id"
RECORD_TOPIC = "oob_invitation"
TAG_NAMES = {"invi_msg_id"}
STATE_INITIAL = "initial"
STATE_AWAIT_RESPONSE = "await_response"
STATE_DONE = "done"
def __init__(
self,
*,
invitation_id: str = None,
state: str = None,
invi_msg_id: str = None,
invitation: Union[InvitationMessage, Mapping] = None, # invitation message
invitation_url: str = None,
public_did: str = None, # backward-compat: BaseRecord.from_storage()
trace: bool = False,
**kwargs,
):
"""Initialize a new InvitationRecord."""
super().__init__(invitation_id, state, trace=trace, **kwargs)
self._id = invitation_id
self.state = state
self.invi_msg_id = invi_msg_id
self._invitation = InvitationMessage.serde(invitation)
self.invitation_url = invitation_url
self.trace = trace
@property
def invitation_id(self) -> str:
"""Accessor for the ID associated with this exchange."""
return self._id
@property
def invitation(self) -> InvitationMessage:
"""Accessor; get deserialized view."""
return None if self._invitation is None else self._invitation.de
@invitation.setter
def invitation(self, value):
"""Setter; store de/serialized views."""
self._invitation = InvitationMessage.serde(value)
@property
def record_value(self) -> dict:
"""Accessor for the JSON record value generated for this invitation."""
return {
**{
prop: getattr(self, prop)
for prop in (
"invitation_url",
"state",
"trace",
)
},
**{
prop: getattr(self, f"_{prop}").ser
for prop in ("invitation",)
if getattr(self, prop) is not None
},
}
def __eq__(self, other: Any) -> bool:
"""Comparison between records."""
return super().__eq__(other)
[docs]class InvitationRecordSchema(BaseExchangeSchema):
"""Schema to allow serialization/deserialization of invitation records."""
invitation_id = fields.Str(
required=False,
description="Invitation record identifier",
example=UUIDFour.EXAMPLE,
)
state = fields.Str(
required=False,
description="Out of band message exchange state",
example=InvitationRecord.STATE_AWAIT_RESPONSE,
)
invi_msg_id = fields.Str(
required=False,
description="Invitation message identifier",
example=UUIDFour.EXAMPLE,
)
invitation = fields.Nested(
InvitationMessageSchema(),
required=False,
description="Out of band invitation message",
)
invitation_url = fields.Str(
required=False,
description="Invitation message URL",
example=(
"https://example.com/endpoint?"
"c_i=eyJAdHlwZSI6ICIuLi4iLCAiLi4uIjogIi4uLiJ9XX0="
),
)