use super::{CloudEngineNodeType, CloudEnginePriceRow};
use ic_platform::Principal;
use ic_platform::candid_codec::Nat;
use serde::Deserialize;
ic_platform::candid_record! {
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
pub(super) struct GetEngineOperatorBySubnetArgs {
1_097_286_461 => pub(super) subnet_id: Option<Principal>,
}
}
ic_platform::candid_record! {
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
pub(super) struct GetEngineOperatorBySubnetResult {
1_645_921_689 => pub(super) engine_operator_id: Option<Principal>,
}
}
ic_platform::candid_record! {
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
pub(super) struct GetEngineOwnerResult {
1_662_346_422 => pub(super) engine_owner: Option<Principal>,
}
}
ic_platform::candid_record! {
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
pub(super) struct GetPlatformAdminResult {
1_090_465_475 => pub(super) platform_admin: Option<Principal>,
}
}
ic_platform::candid_record! {
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
pub(super) struct CaffeineSettings {
2_117_141_633 => pub(super) enabled: Option<bool>,
}
}
ic_platform::candid_record! {
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
pub(super) struct GetCaffeineSettingsResult {
2_336_062_691 => pub(super) settings: Option<CaffeineSettings>,
}
}
ic_platform::candid_record! {
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
pub(super) struct ListDomainsResult {
2_736_417_455 => pub(super) domains: Option<Vec<String>>,
}
}
ic_platform::candid_record! {
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
struct CloudEnginePriceWire {
2_625_678_760 => gross_cycles: Nat,
3_039_038_447 => net_cycles: Nat,
}
}
ic_platform::candid_record! {
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
struct CloudEnginePriceEntryWire {
22_399 => dc: Option<String>,
272_465_847 => updated_at: i64,
287_472_983 => node_type: NodeType,
590_999_857 => provider: Option<Principal>,
3_364_572_809 => price: CloudEnginePriceWire,
}
}
ic_platform::candid_record! {
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
pub(super) struct CloudEngineMarketplaceEntryWire {
5_343_647 => key: String,
1_887_860_850 => entry: CloudEnginePriceEntryWire,
}
}
impl CloudEngineMarketplaceEntryWire {
pub(super) fn into_report_row(self) -> CloudEnginePriceRow {
CloudEnginePriceRow {
key: self.key,
node_type: self.entry.node_type.into(),
data_center_id: self.entry.dc,
provider_id: self.entry.provider.map(|principal| principal.to_text()),
net_cycles_per_month: self.entry.price.net_cycles.0.to_str_radix(10),
gross_cycles_per_month: self.entry.price.gross_cycles.0.to_str_radix(10),
updated_at_unix_nanos: self.entry.updated_at,
}
}
}
#[cfg(test)]
mod tests;
ic_platform::candid_variant! {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize)]
enum NodeType {
#[serde(rename = "type4_1")]
4_172_531_116 => Type4_1,
#[serde(rename = "type4_2")]
4_172_531_117 => Type4_2,
#[serde(rename = "type4_3")]
4_172_531_118 => Type4_3,
#[serde(rename = "type4_4")]
4_172_531_119 => Type4_4,
#[serde(rename = "type4_5")]
4_172_531_120 => Type4_5,
}
}
impl From<NodeType> for CloudEngineNodeType {
fn from(value: NodeType) -> Self {
match value {
NodeType::Type4_1 => Self::Type4_1,
NodeType::Type4_2 => Self::Type4_2,
NodeType::Type4_3 => Self::Type4_3,
NodeType::Type4_4 => Self::Type4_4,
NodeType::Type4_5 => Self::Type4_5,
}
}
}