tap_msg/message/
update_policies.rs1use crate::error::{Error, Result};
7use crate::message::policy::Policy;
8use crate::TapMessage;
9use serde::{Deserialize, Serialize};
10
11#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
15#[tap(
16 message_type = "https://tap.rsvp/schema/1.0#UpdatePolicies",
17 custom_validation
18)]
19pub struct UpdatePolicies {
20 #[tap(thread_id)]
21 pub transaction_id: String,
22
23 pub policies: Vec<Policy>,
24}
25
26impl UpdatePolicies {
27 pub fn new(transaction_id: &str, policies: Vec<Policy>) -> Self {
29 Self {
30 transaction_id: transaction_id.to_string(),
31 policies,
32 }
33 }
34
35 pub fn validate_updatepolicies(&self) -> Result<()> {
37 if self.transaction_id.is_empty() {
38 return Err(Error::Validation(
39 "UpdatePolicies must have a transaction_id".to_string(),
40 ));
41 }
42
43 if self.policies.is_empty() {
44 return Err(Error::Validation(
45 "UpdatePolicies must have at least one policy".to_string(),
46 ));
47 }
48
49 for policy in &self.policies {
50 policy.validate()?;
51 }
52
53 Ok(())
54 }
55}