tap_msg/message/
relationship.rs1use crate::error::{Error, Result};
7use crate::TapMessage;
8use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
14#[tap(message_type = "https://tap.rsvp/schema/1.0#ConfirmRelationship")]
15pub struct ConfirmRelationship {
16 #[serde(rename = "transfer_id")]
18 #[tap(thread_id)]
19 pub transaction_id: String,
20
21 #[serde(rename = "@id")]
23 pub agent_id: String,
24
25 #[serde(rename = "for")]
27 pub for_entity: String,
28
29 #[serde(skip_serializing_if = "Option::is_none")]
31 pub role: Option<String>,
32}
33
34impl ConfirmRelationship {
35 pub fn new(transaction_id: &str, agent_id: &str, for_entity: &str) -> Self {
37 Self {
38 transaction_id: transaction_id.to_string(),
39 agent_id: agent_id.to_string(),
40 for_entity: for_entity.to_string(),
41 role: None,
42 }
43 }
44
45 pub fn with_role(mut self, role: &str) -> Self {
47 self.role = Some(role.to_string());
48 self
49 }
50}
51
52impl ConfirmRelationship {
55 pub fn validate_relationship(&self) -> Result<()> {
57 if self.transaction_id.is_empty() {
58 return Err(Error::Validation(
59 "Transfer ID is required in ConfirmRelationship".to_string(),
60 ));
61 }
62
63 if self.agent_id.is_empty() {
64 return Err(Error::Validation(
65 "Agent ID (@id) is required in ConfirmRelationship".to_string(),
66 ));
67 }
68
69 if self.for_entity.is_empty() {
70 return Err(Error::Validation(
71 "For entity is required in ConfirmRelationship".to_string(),
72 ));
73 }
74
75 Ok(())
76 }
77}