use std::fmt;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum AssignmentMethod {
Virtual,
Collect,
}
impl AssignmentMethod {
pub fn as_str(&self) -> &'static str {
match self {
AssignmentMethod::Virtual => "virtual",
AssignmentMethod::Collect => "collect",
}
}
}
impl fmt::Display for AssignmentMethod {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum VerificationMethod {
Email,
Whatsapp,
Bypass,
#[serde(untagged)]
Other(String),
}
impl VerificationMethod {
pub fn as_str(&self) -> &str {
match self {
VerificationMethod::Email => "Email",
VerificationMethod::Whatsapp => "Whatsapp",
VerificationMethod::Bypass => "Bypass",
VerificationMethod::Other(s) => s.as_str(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum NotificationMethod {
Email,
Whatsapp,
#[serde(untagged)]
Other(String),
}
impl NotificationMethod {
pub fn as_str(&self) -> &str {
match self {
NotificationMethod::Email => "Email",
NotificationMethod::Whatsapp => "Whatsapp",
NotificationMethod::Other(s) => s.as_str(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum NotificationStatus {
Sent,
Failed,
#[serde(untagged)]
Other(String),
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum NotificationEvent {
SignatureRequest,
DocumentAboutToExpire,
DocumentExpired,
DocumentCanceled,
DocumentDeclined,
SignedDelivery,
#[serde(untagged)]
Unknown(String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct NotificationHistoryEntry {
pub event: NotificationEvent,
pub status: NotificationStatus,
#[serde(default)]
pub error_code: Option<String>,
#[serde(default)]
pub error_message: Option<String>,
#[serde(default)]
pub sent_at: Option<String>,
#[serde(default)]
pub failed_at: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AssignmentSigner {
pub id: String,
pub full_name: String,
#[serde(default)]
pub email: Option<String>,
#[serde(default)]
pub whatsapp_phone_number: Option<String>,
#[serde(default)]
pub has_accepted_terms: bool,
#[serde(default)]
pub verification_method: Option<VerificationMethod>,
#[serde(default)]
pub notification_methods: Option<Vec<NotificationMethod>>,
#[serde(default)]
pub step: Option<u32>,
#[serde(default)]
pub notified: Option<bool>,
#[serde(default)]
pub completed: Option<bool>,
#[serde(default)]
pub notification_history: Vec<NotificationHistoryEntry>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CopyReceiver {
pub id: String,
pub full_name: String,
#[serde(default)]
pub email: Option<String>,
#[serde(default)]
pub whatsapp_phone_number: Option<String>,
#[serde(default)]
pub has_accepted_terms: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AssignmentItem {
pub id: String,
#[serde(default)]
pub page: Option<serde_json::Value>,
#[serde(default)]
pub signer: Option<serde_json::Value>,
#[serde(default)]
pub field: Option<serde_json::Value>,
#[serde(default)]
pub display_settings: Option<serde_json::Value>,
#[serde(default)]
pub value: Option<serde_json::Value>,
#[serde(default)]
pub completed: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SigningUrl {
pub signer_id: String,
pub url: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AssignmentSummary {
pub signer_count: u32,
pub completed_count: u32,
#[serde(default)]
pub signers: Vec<AssignmentSummarySigner>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AssignmentSummarySigner {
pub id: String,
pub full_name: String,
#[serde(default)]
pub email: Option<String>,
#[serde(default)]
pub has_accepted_terms: bool,
pub completed: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Assignment {
#[serde(default)]
pub resource: Option<String>,
pub id: String,
#[serde(default)]
pub document_id: Option<String>,
#[serde(default)]
pub sender_email: Option<String>,
#[serde(default)]
pub method: Option<AssignmentMethod>,
#[serde(default)]
pub status: Option<String>,
#[serde(default)]
pub expiration: Option<String>,
#[serde(default)]
pub expires_at: Option<String>,
#[serde(default)]
pub message: Option<String>,
#[serde(default)]
pub signers: Vec<AssignmentSigner>,
#[serde(default)]
pub copy_receivers: Vec<CopyReceiver>,
#[serde(default)]
pub items: Vec<AssignmentItem>,
#[serde(default)]
pub summary: Option<AssignmentSummary>,
#[serde(default)]
pub signing_urls: Vec<SigningUrl>,
#[serde(default)]
pub completed_at: Option<serde_json::Value>,
#[serde(default)]
pub created_at: Option<serde_json::Value>,
#[serde(default)]
pub updated_at: Option<serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ResendNotificationResult {
#[serde(default)]
pub is_sent: bool,
#[serde(default)]
pub document_id: Option<String>,
#[serde(default)]
pub signer_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ResendCostBreakdownItem {
pub code: String,
pub name: String,
pub cost: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ResendCostEstimate {
pub total: f64,
#[serde(default)]
pub breakdown: Vec<ResendCostBreakdownItem>,
pub credit_balance: f64,
pub has_sufficient_credits: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SignDocumentItem {
#[serde(rename = "itemId")]
pub item_id: String,
#[serde(rename = "fieldId")]
pub field_id: String,
#[serde(rename = "pageId")]
pub page_id: String,
pub value: String,
}
impl SignDocumentItem {
pub fn new<I, F, P, V>(item_id: I, field_id: F, page_id: P, value: V) -> Self
where
I: Into<String>,
F: Into<String>,
P: Into<String>,
V: Into<String>,
{
Self {
item_id: item_id.into(),
field_id: field_id.into(),
page_id: page_id.into(),
value: value.into(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct WhatsAppNotification {
pub sent_at: serde_json::Value,
pub header: String,
pub body: String,
#[serde(default)]
pub buttons: Vec<WhatsAppButton>,
pub phone_number: String,
pub signer_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct WhatsAppButton {
pub text: String,
#[serde(default)]
pub url: Option<String>,
}