tap_msg/message/
relationship.rs

1//! Relationship confirmation message types for the Transaction Authorization Protocol.
2//!
3//! This module defines the ConfirmRelationship message type, which is used to confirm
4//! relationships between agents in the TAP protocol.
5
6use crate::error::{Error, Result};
7use crate::TapMessage;
8use serde::{Deserialize, Serialize};
9
10/// ConfirmRelationship message body (TAIP-9).
11///
12/// This message type allows confirming a relationship between agents.
13#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
14#[tap(message_type = "https://tap.rsvp/schema/1.0#ConfirmRelationship")]
15pub struct ConfirmRelationship {
16    /// ID of the transaction related to this message.
17    #[serde(rename = "transfer_id")]
18    #[tap(thread_id)]
19    pub transaction_id: String,
20
21    /// DID of the agent whose relationship is being confirmed.
22    pub agent_id: String,
23
24    /// Type of relationship being confirmed (e.g., "agent_for", "custodian", etc.).
25    pub relationship_type: String,
26}
27
28impl ConfirmRelationship {
29    /// Creates a new ConfirmRelationship message body.
30    pub fn new(transaction_id: &str, agent_id: &str, relationship_type: &str) -> Self {
31        Self {
32            transaction_id: transaction_id.to_string(),
33            agent_id: agent_id.to_string(),
34            relationship_type: relationship_type.to_string(),
35        }
36    }
37}
38
39// Note: The validate() method name conflicts with auto-generated validate,
40// so we rename the custom one
41impl ConfirmRelationship {
42    /// Custom validation for ConfirmRelationship messages
43    pub fn validate_relationship(&self) -> Result<()> {
44        if self.transaction_id.is_empty() {
45            return Err(Error::Validation(
46                "Transfer ID is required in ConfirmRelationship".to_string(),
47            ));
48        }
49
50        if self.agent_id.is_empty() {
51            return Err(Error::Validation(
52                "Agent ID is required in ConfirmRelationship".to_string(),
53            ));
54        }
55
56        if self.relationship_type.is_empty() {
57            return Err(Error::Validation(
58                "Relationship type is required in ConfirmRelationship".to_string(),
59            ));
60        }
61
62        Ok(())
63    }
64}