use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use crate::model::{Argument, ArgumentSchema, IdentityDescriptor, Version};
use crate::value::LocalizedString;
use crate::{SourceCatalog, TroxValueError};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct SourceMessageRef {
pub contract_signature: String,
pub entry_id: String,
pub format: String,
pub source_signature: String,
pub version: Version,
}
#[derive(Debug, Clone)]
pub struct SourceMessage {
pub(crate) catalog: SourceCatalog,
pub(crate) argument_schemas: BTreeMap<String, ArgumentSchema>,
pub(crate) identity: IdentityDescriptor,
pub(crate) reference: SourceMessageRef,
}
impl SourceMessage {
pub fn argument_schemas(&self) -> &BTreeMap<String, ArgumentSchema> {
&self.argument_schemas
}
pub fn source_ref(&self) -> &SourceMessageRef {
&self.reference
}
pub fn bind(
&self,
arguments: BTreeMap<String, Argument>,
) -> Result<LocalizedString, TroxValueError> {
self.catalog.bind_source_message(self, arguments)
}
}
impl SourceMessageRef {
pub fn to_canonical_json(&self) -> Result<String, crate::SerializeError> {
crate::canonical::canonical_json(self)
}
}