use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use crate::{ComponentId, LinkName, Result, WitNamespace, WitPackage};
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[non_exhaustive]
pub struct ComponentAuctionAck {
#[serde(default)]
pub(crate) component_ref: String,
#[serde(default)]
pub(crate) component_id: String,
#[serde(default)]
pub(crate) host_id: String,
#[serde(default)]
pub(crate) constraints: BTreeMap<String, String>,
}
impl ComponentAuctionAck {
#[must_use]
pub fn from_component_host_and_constraints(
component_ref: &str,
component_id: &str,
host_id: &str,
constraints: impl Into<BTreeMap<String, String>>,
) -> Self {
Self {
component_ref: component_ref.into(),
component_id: component_id.into(),
host_id: host_id.into(),
constraints: constraints.into(),
}
}
#[must_use]
pub fn component_ref(&self) -> &str {
self.component_ref.as_ref()
}
#[must_use]
pub fn component_id(&self) -> &str {
self.component_ref.as_ref()
}
#[must_use]
pub fn host_id(&self) -> &str {
self.host_id.as_ref()
}
#[must_use]
pub fn constraints(&self) -> &BTreeMap<String, String> {
&self.constraints
}
pub fn builder() -> ComponentAuctionAckBuilder {
ComponentAuctionAckBuilder::default()
}
}
#[derive(Default, Clone, PartialEq, Eq)]
pub struct ComponentAuctionAckBuilder {
component_ref: Option<String>,
component_id: Option<String>,
host_id: Option<String>,
constraints: Option<BTreeMap<String, String>>,
}
impl ComponentAuctionAckBuilder {
#[must_use]
pub fn component_ref(mut self, v: String) -> Self {
self.component_ref = Some(v);
self
}
#[must_use]
pub fn component_id(mut self, v: String) -> Self {
self.component_id = Some(v);
self
}
#[must_use]
pub fn host_id(mut self, v: String) -> Self {
self.host_id = Some(v);
self
}
#[must_use]
pub fn constraints(mut self, v: BTreeMap<String, String>) -> Self {
self.constraints = Some(v);
self
}
pub fn build(self) -> Result<ComponentAuctionAck> {
Ok(ComponentAuctionAck {
component_ref: self
.component_ref
.ok_or_else(|| "component_ref is required".to_string())?,
component_id: self
.component_id
.ok_or_else(|| "component_id is required".to_string())?,
host_id: self
.host_id
.ok_or_else(|| "host_id is required".to_string())?,
constraints: self.constraints.unwrap_or_default(),
})
}
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[non_exhaustive]
pub struct ComponentAuctionRequest {
#[serde(default)]
pub(crate) component_ref: String,
pub(crate) component_id: ComponentId,
pub(crate) constraints: BTreeMap<String, String>,
}
impl ComponentAuctionRequest {
#[must_use]
pub fn component_ref(&self) -> &str {
self.component_ref.as_ref()
}
#[must_use]
pub fn component_id(&self) -> &str {
self.component_ref.as_ref()
}
#[must_use]
pub fn constraints(&self) -> &BTreeMap<String, String> {
&self.constraints
}
pub fn builder() -> ComponentAuctionRequestBuilder {
ComponentAuctionRequestBuilder::default()
}
}
#[derive(Default, Clone, PartialEq, Eq)]
pub struct ComponentAuctionRequestBuilder {
component_ref: Option<String>,
component_id: Option<ComponentId>,
constraints: Option<BTreeMap<String, String>>,
}
impl ComponentAuctionRequestBuilder {
#[must_use]
pub fn component_ref(mut self, v: String) -> Self {
self.component_ref = Some(v);
self
}
#[must_use]
pub fn component_id(mut self, v: String) -> Self {
self.component_id = Some(v);
self
}
#[must_use]
pub fn constraints(mut self, v: BTreeMap<String, String>) -> Self {
self.constraints = Some(v);
self
}
pub fn build(self) -> Result<ComponentAuctionRequest> {
Ok(ComponentAuctionRequest {
component_ref: self
.component_ref
.ok_or_else(|| "component_ref is required".to_string())?,
component_id: self
.component_id
.ok_or_else(|| "component_id is required".to_string())?,
constraints: self.constraints.unwrap_or_default(),
})
}
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[non_exhaustive]
pub struct ProviderAuctionAck {
#[serde(default)]
pub(crate) host_id: String,
#[serde(default)]
pub(crate) provider_ref: String,
#[serde(default)]
pub(crate) provider_id: String,
#[serde(default)]
pub(crate) constraints: BTreeMap<String, String>,
}
impl ProviderAuctionAck {
#[must_use]
pub fn host_id(&self) -> &str {
self.host_id.as_ref()
}
#[must_use]
pub fn provider_ref(&self) -> &str {
self.provider_ref.as_ref()
}
#[must_use]
pub fn provider_id(&self) -> &str {
self.provider_id.as_ref()
}
#[must_use]
pub fn constraints(&self) -> &BTreeMap<String, String> {
&self.constraints
}
#[must_use]
pub fn builder() -> ProviderAuctionAckBuilder {
ProviderAuctionAckBuilder::default()
}
}
#[derive(Default, Clone, PartialEq, Eq)]
pub struct ProviderAuctionAckBuilder {
host_id: Option<String>,
provider_ref: Option<String>,
provider_id: Option<String>,
constraints: Option<BTreeMap<String, String>>,
}
impl ProviderAuctionAckBuilder {
#[must_use]
pub fn provider_ref(mut self, v: String) -> Self {
self.provider_ref = Some(v);
self
}
#[must_use]
pub fn provider_id(mut self, v: String) -> Self {
self.provider_id = Some(v);
self
}
#[must_use]
pub fn host_id(mut self, v: String) -> Self {
self.host_id = Some(v);
self
}
#[must_use]
pub fn constraints(mut self, v: BTreeMap<String, String>) -> Self {
self.constraints = Some(v);
self
}
pub fn build(self) -> Result<ProviderAuctionAck> {
Ok(ProviderAuctionAck {
provider_ref: self
.provider_ref
.ok_or_else(|| "provider_ref is required".to_string())?,
provider_id: self
.provider_id
.ok_or_else(|| "provider_id is required".to_string())?,
host_id: self
.host_id
.ok_or_else(|| "host_id is required".to_string())?,
constraints: self.constraints.unwrap_or_default(),
})
}
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct ProviderAuctionRequest {
#[serde(default)]
pub(crate) provider_ref: String,
pub(crate) provider_id: ComponentId,
pub(crate) constraints: BTreeMap<String, String>,
}
impl ProviderAuctionRequest {
#[must_use]
pub fn provider_ref(&self) -> &str {
self.provider_ref.as_ref()
}
#[must_use]
pub fn provider_id(&self) -> &str {
self.provider_id.as_ref()
}
#[must_use]
pub fn constraints(&self) -> &BTreeMap<String, String> {
&self.constraints
}
#[must_use]
pub fn builder() -> ProviderAuctionRequestBuilder {
ProviderAuctionRequestBuilder::default()
}
}
#[derive(Default, Clone, PartialEq, Eq)]
pub struct ProviderAuctionRequestBuilder {
provider_ref: Option<String>,
provider_id: Option<ComponentId>,
constraints: Option<BTreeMap<String, String>>,
}
impl ProviderAuctionRequestBuilder {
#[must_use]
pub fn provider_ref(mut self, v: String) -> Self {
self.provider_ref = Some(v);
self
}
#[must_use]
pub fn provider_id(mut self, v: String) -> Self {
self.provider_id = Some(v);
self
}
#[must_use]
pub fn constraints(mut self, v: BTreeMap<String, String>) -> Self {
self.constraints = Some(v);
self
}
pub fn build(self) -> Result<ProviderAuctionRequest> {
Ok(ProviderAuctionRequest {
provider_ref: self
.provider_ref
.ok_or_else(|| "provider_ref is required".to_string())?,
provider_id: self
.provider_id
.ok_or_else(|| "provider_id is required".to_string())?,
constraints: self.constraints.unwrap_or_default(),
})
}
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[non_exhaustive]
pub struct DeleteInterfaceLinkDefinitionRequest {
pub(crate) source_id: ComponentId,
#[serde(default = "default_link_name")]
pub(crate) name: LinkName,
pub(crate) wit_namespace: WitNamespace,
pub(crate) wit_package: WitPackage,
}
impl DeleteInterfaceLinkDefinitionRequest {
pub fn from_source_and_link_metadata(
source_id: &str,
name: &str,
wit_ns: &str,
wit_pkg: &str,
) -> Self {
Self {
source_id: source_id.into(),
name: name.into(),
wit_namespace: wit_ns.into(),
wit_package: wit_pkg.into(),
}
}
#[must_use]
pub fn source_id(&self) -> &str {
self.source_id.as_ref()
}
#[must_use]
pub fn link_name(&self) -> &str {
self.name.as_ref()
}
#[must_use]
pub fn wit_namespace(&self) -> &str {
self.wit_namespace.as_ref()
}
#[must_use]
pub fn wit_package(&self) -> &str {
self.wit_package.as_ref()
}
#[must_use]
pub fn builder() -> DeleteInterfaceLinkDefinitionRequestBuilder {
DeleteInterfaceLinkDefinitionRequestBuilder::default()
}
}
#[derive(Default, Clone, PartialEq, Eq)]
pub struct DeleteInterfaceLinkDefinitionRequestBuilder {
source_id: Option<ComponentId>,
name: Option<LinkName>,
wit_namespace: Option<WitNamespace>,
wit_package: Option<WitPackage>,
}
impl DeleteInterfaceLinkDefinitionRequestBuilder {
pub fn source_id(mut self, v: String) -> Self {
self.source_id = Some(v);
self
}
pub fn name(mut self, v: String) -> Self {
self.name = Some(v);
self
}
pub fn wit_namespace(mut self, v: String) -> Self {
self.wit_namespace = Some(v);
self
}
pub fn wit_package(mut self, v: String) -> Self {
self.wit_package = Some(v);
self
}
pub fn build(self) -> Result<DeleteInterfaceLinkDefinitionRequest> {
Ok(DeleteInterfaceLinkDefinitionRequest {
source_id: self
.source_id
.ok_or_else(|| "source_id is required".to_string())?,
name: self.name.ok_or_else(|| "name is required".to_string())?,
wit_namespace: self
.wit_namespace
.ok_or_else(|| "wit_namespace is required".to_string())?,
wit_package: self
.wit_package
.ok_or_else(|| "wit_package is required".to_string())?,
})
}
}
fn default_link_name() -> LinkName {
"default".to_string()
}
#[cfg(test)]
mod tests {
use std::collections::BTreeMap;
use super::{
ComponentAuctionAck, ComponentAuctionRequest, DeleteInterfaceLinkDefinitionRequest,
ProviderAuctionAck, ProviderAuctionRequest,
};
#[test]
fn component_auction_ack_builder() {
assert_eq!(
ComponentAuctionAck {
component_ref: "component_ref".into(),
component_id: "component_id".into(),
host_id: "host_id".into(),
constraints: BTreeMap::from([("a".into(), "b".into())])
},
ComponentAuctionAck::builder()
.component_ref("component_ref".into())
.component_id("component_id".into())
.host_id("host_id".into())
.constraints(BTreeMap::from([("a".into(), "b".into())]))
.build()
.unwrap()
)
}
#[test]
fn component_auction_request_builder() {
assert_eq!(
ComponentAuctionRequest {
component_ref: "component_ref".into(),
component_id: "component_id".into(),
constraints: BTreeMap::from([("a".into(), "b".into())])
},
ComponentAuctionRequest::builder()
.component_ref("component_ref".into())
.component_id("component_id".into())
.constraints(BTreeMap::from([("a".into(), "b".into())]))
.build()
.unwrap()
)
}
#[test]
fn provider_auction_ack_builder() {
assert_eq!(
ProviderAuctionAck {
provider_ref: "provider_ref".into(),
provider_id: "provider_id".into(),
host_id: "host_id".into(),
constraints: BTreeMap::from([("a".into(), "b".into())])
},
ProviderAuctionAck::builder()
.provider_ref("provider_ref".into())
.provider_id("provider_id".into())
.host_id("host_id".into())
.constraints(BTreeMap::from([("a".into(), "b".into())]))
.build()
.unwrap()
)
}
#[test]
fn provider_auction_request_builder() {
assert_eq!(
ProviderAuctionRequest {
provider_ref: "provider_ref".into(),
provider_id: "provider_id".into(),
constraints: BTreeMap::from([("a".into(), "b".into())])
},
ProviderAuctionRequest::builder()
.provider_ref("provider_ref".into())
.provider_id("provider_id".into())
.constraints(BTreeMap::from([("a".into(), "b".into())]))
.build()
.unwrap()
)
}
#[test]
fn delete_interface_link_definition_request_builder() {
assert_eq!(
DeleteInterfaceLinkDefinitionRequest {
source_id: "source_id".into(),
name: "name".into(),
wit_namespace: "wit_namespace".into(),
wit_package: "wit_package".into(),
},
DeleteInterfaceLinkDefinitionRequest::builder()
.source_id("source_id".into())
.name("name".into())
.wit_namespace("wit_namespace".into())
.wit_package("wit_package".into())
.build()
.unwrap()
)
}
}