use crate::error::{Error, Result};
use crate::message::agent::TapParticipant;
use crate::message::Party;
use crate::TapMessage;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
#[tap(message_type = "https://tap.rsvp/schema/1.0#UpdateParty")]
pub struct UpdateParty {
#[tap(thread_id)]
pub transaction_id: String,
#[serde(rename = "partyType")]
pub party_type: String,
#[tap(participant)]
pub party: Party,
#[serde(rename = "@context", skip_serializing_if = "Option::is_none")]
pub context: Option<String>,
}
impl UpdateParty {
pub fn new(transaction_id: &str, party_type: &str, party: Party) -> Self {
Self {
transaction_id: transaction_id.to_string(),
party_type: party_type.to_string(),
party,
context: None,
}
}
pub fn validate_update_party(&self) -> Result<()> {
if self.transaction_id.is_empty() {
return Err(Error::Validation(
"transaction_id cannot be empty".to_string(),
));
}
if self.party_type.is_empty() {
return Err(Error::Validation("partyType cannot be empty".to_string()));
}
if self.party.id().is_empty() {
return Err(Error::Validation("party.id cannot be empty".to_string()));
}
Ok(())
}
}
impl UpdateParty {
pub fn validate(&self) -> Result<()> {
self.validate_update_party()
}
}