use serde::{Deserialize, Serialize};
use crate::error::{Error, Result};
use crate::TapMessage;
#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
#[tap(message_type = "https://tap.rsvp/schema/1.0#Revert")]
pub struct Revert {
#[tap(thread_id)]
pub transaction_id: String,
#[serde(rename = "settlementAddress")]
pub settlement_address: String,
pub reason: String,
}
impl Revert {
pub fn new(transaction_id: &str, settlement_address: &str, reason: &str) -> Self {
Self {
transaction_id: transaction_id.to_string(),
settlement_address: settlement_address.to_string(),
reason: reason.to_string(),
}
}
}
impl Revert {
pub fn validate_revert(&self) -> Result<()> {
if self.transaction_id.is_empty() {
return Err(Error::Validation(
"Transaction ID is required in Revert".to_string(),
));
}
if self.settlement_address.is_empty() {
return Err(Error::Validation(
"Settlement address is required in Revert".to_string(),
));
}
if self.reason.is_empty() {
return Err(Error::Validation(
"Reason is required in Revert".to_string(),
));
}
Ok(())
}
}