1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use super::Result;
use std::collections::BTreeMap;

#[derive(Default, Serialize, Deserialize, Clone, Debug)]
#[cfg_attr(feature = "filesystem", serde(deny_unknown_fields))]
pub struct EventDefinition {
    pub key: String,
    pub value: String,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EventStream {
    pub name: String,

    #[serde(default)]
    pub producers: Vec<String>,

    #[serde(default)]
    pub consumers: Vec<String>,

    pub event_definitions: Vec<EventDefinition>,

    #[serde(default)]
    pub config: BTreeMap<String, String>,
}

impl EventStream {
    pub fn verify(&self) -> Result<()> {
        if self.event_definitions.is_empty() {
            bail!("Event definitions must not be empty when EventStreams is specified");
        }
        if self.name.is_empty() {
            bail!("EventStream name must not be empty when EventStreams is specified");
        }
        Ok(())
    }
}