use serde::{Deserialize, Serialize};
use crate::error::{Error, Result};
use crate::message::agent::TapParticipant;
use crate::message::Agent;
use crate::TapMessage;
#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
#[tap(
message_type = "https://tap.rsvp/schema/1.0#AddAgents",
custom_validation
)]
pub struct AddAgents {
#[tap(thread_id)]
pub transaction_id: String,
#[tap(participant_list)]
pub agents: Vec<Agent>,
}
impl AddAgents {
pub fn new(transaction_id: &str, agents: Vec<Agent>) -> Self {
Self {
transaction_id: transaction_id.to_string(),
agents,
}
}
pub fn add_agent(mut self, agent: Agent) -> Self {
self.agents.push(agent);
self
}
}
impl AddAgents {
pub fn validate_addagents(&self) -> Result<()> {
if self.transaction_id.is_empty() {
return Err(Error::Validation(
"Transaction ID is required in AddAgents".to_string(),
));
}
if self.agents.is_empty() {
return Err(Error::Validation(
"At least one agent must be specified in AddAgents".to_string(),
));
}
for agent in &self.agents {
if agent.id().is_empty() {
return Err(Error::Validation("Agent ID cannot be empty".to_string()));
}
}
Ok(())
}
}
#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
#[tap(
message_type = "https://tap.rsvp/schema/1.0#ReplaceAgent",
custom_validation
)]
pub struct ReplaceAgent {
#[tap(thread_id)]
pub transaction_id: String,
pub original: String,
#[tap(participant)]
pub replacement: Agent,
}
impl ReplaceAgent {
pub fn new(transaction_id: &str, original: &str, replacement: Agent) -> Self {
Self {
transaction_id: transaction_id.to_string(),
original: original.to_string(),
replacement,
}
}
}
impl ReplaceAgent {
pub fn validate_replaceagent(&self) -> Result<()> {
if self.transaction_id.is_empty() {
return Err(Error::Validation(
"Transaction ID is required in ReplaceAgent".to_string(),
));
}
if self.original.is_empty() {
return Err(Error::Validation(
"Original agent ID is required in ReplaceAgent".to_string(),
));
}
if self.replacement.id().is_empty() {
return Err(Error::Validation(
"Replacement agent ID is required in ReplaceAgent".to_string(),
));
}
Ok(())
}
}
#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
#[tap(
message_type = "https://tap.rsvp/schema/1.0#RemoveAgent",
custom_validation
)]
pub struct RemoveAgent {
#[tap(thread_id)]
pub transaction_id: String,
pub agent: String,
}
impl RemoveAgent {
pub fn new(transaction_id: &str, agent: &str) -> Self {
Self {
transaction_id: transaction_id.to_string(),
agent: agent.to_string(),
}
}
}
impl RemoveAgent {
pub fn validate_removeagent(&self) -> Result<()> {
if self.transaction_id.is_empty() {
return Err(Error::Validation(
"Transaction ID is required in RemoveAgent".to_string(),
));
}
if self.agent.is_empty() {
return Err(Error::Validation(
"Agent ID is required in RemoveAgent".to_string(),
));
}
Ok(())
}
}