1use crate::dto::prelude::*;
2
3pub use crate::domain::state::{FleetMode, FleetStatus};
4
5#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
10pub enum FleetCommand {
11 SetStatus(FleetStatus),
12 SetCyclesFundingEnabled(bool),
13}
14
15#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
20pub enum FleetCommandResponse {
21 Status(SetStateResponse<FleetStatus>),
22 CyclesFundingEnabled(SetStateResponse<bool>),
23}
24
25#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
30pub struct SetStateResponse<T> {
31 pub previous: T,
32 pub current: T,
33 pub changed: bool,
34}
35
36#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
41pub struct FleetStateInput {
42 pub mode: FleetMode,
43 pub cycles_funding_enabled: bool,
44}
45
46#[derive(CandidType, Deserialize)]
51pub struct FleetStateResponse {
52 pub mode: FleetMode,
53 pub cycles_funding_enabled: bool,
54}
55
56#[derive(CandidType, Clone, Debug, Deserialize, Eq, PartialEq)]
61pub struct BootstrapStatusResponse {
62 pub ready: bool,
63 pub phase: String,
64 pub last_error: Option<String>,
65}
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70 use candid::{Decode, Encode};
71 use serde::de::DeserializeOwned;
72 use std::fmt::Debug;
73
74 #[test]
75 fn fleet_mode_roundtrips_candid_through_dto_path() {
76 assert_enum_candid_contract(FleetMode::Readonly);
77 }
78
79 #[test]
80 fn fleet_status_roundtrips_candid_through_dto_path() {
81 assert_enum_candid_contract(FleetStatus::Readonly);
82 }
83
84 fn assert_enum_candid_contract<T>(value: T)
85 where
86 T: CandidType + Clone + Debug + DeserializeOwned + Eq,
87 {
88 let bytes = Encode!(&value).expect("encode state enum");
89 let decoded = Decode!(&bytes, T).expect("decode state enum");
90
91 assert_eq!(decoded, value);
92 }
93}