1use serde::{Deserialize, Serialize};
4use serde_json::Value;
5use std::collections::HashMap;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Service {
11 pub id: String,
13
14 #[serde(rename = "type")]
16 pub type_: ServiceType,
17
18 pub service_endpoint: ServiceEndpoint,
20
21 #[serde(flatten)]
23 pub properties: HashMap<String, Value>,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum ServiceType {
30 Single(String),
31 Multiple(Vec<String>),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ServiceEndpoint {
38 Uri(String),
39 Multiple(Vec<String>),
40 Map(HashMap<String, Value>),
41}
42
43impl Service {
44 pub fn new(id: String, type_: String, endpoint: String) -> Self {
46 Self {
47 id,
48 type_: ServiceType::Single(type_),
49 service_endpoint: ServiceEndpoint::Uri(endpoint),
50 properties: HashMap::new(),
51 }
52 }
53
54 pub fn hanzo_node(did: &str, endpoint: String) -> Self {
56 Self::new(
57 format!("{did}#hanzo-node"),
58 "HanzoNode".to_string(),
59 endpoint,
60 )
61 }
62
63 pub fn llm_provider(did: &str, endpoint: String) -> Self {
65 Self::new(
66 format!("{did}#llm-provider"),
67 "LLMProvider".to_string(),
68 endpoint,
69 )
70 }
71
72 pub fn messaging(did: &str, endpoint: String) -> Self {
74 Self::new(
75 format!("{did}#messaging"),
76 "MessagingService".to_string(),
77 endpoint,
78 )
79 }
80}