use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Service {
pub id: String,
#[serde(rename = "type")]
pub type_: ServiceType,
pub service_endpoint: ServiceEndpoint,
#[serde(flatten)]
pub properties: HashMap<String, Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ServiceType {
Single(String),
Multiple(Vec<String>),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ServiceEndpoint {
Uri(String),
Multiple(Vec<String>),
Map(HashMap<String, Value>),
}
impl Service {
pub fn new(id: String, type_: String, endpoint: String) -> Self {
Self {
id,
type_: ServiceType::Single(type_),
service_endpoint: ServiceEndpoint::Uri(endpoint),
properties: HashMap::new(),
}
}
pub fn hanzo_node(did: &str, endpoint: String) -> Self {
Self::new(
format!("{did}#hanzo-node"),
"HanzoNode".to_string(),
endpoint,
)
}
pub fn llm_provider(did: &str, endpoint: String) -> Self {
Self::new(
format!("{did}#llm-provider"),
"LLMProvider".to_string(),
endpoint,
)
}
pub fn messaging(did: &str, endpoint: String) -> Self {
Self::new(
format!("{did}#messaging"),
"MessagingService".to_string(),
endpoint,
)
}
}