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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
    Appellation: interface <module>
    Creator: FL03 <jo3mccain@icloud.com>
    Description:
        ... Summary ...
*/
use crate::{api, cli, handlers::handle_cli_inputs};
use acme::prelude::{async_trait, APISpec, CLISpec};
use scsys::{BoxResult, Temporal};

#[derive(Clone, Copy, Debug, Hash, PartialEq, scsys::Deserialize, scsys::Serialize)]
pub enum AppState {
    Off,
    On,
}

impl Default for AppState {
    fn default() -> Self {
        Self::Off
    }
}

#[derive(Clone, Debug, Hash, PartialEq, scsys::Deserialize, scsys::Serialize)]
pub struct Flow {
    pub state: AppState,
    pub timestamp: i64,
}

impl Flow {
    fn constructor(state: AppState, timestamp: i64) -> Self {
        Self { state, timestamp }
    }
    pub fn new(state: AppState) -> Self {
        Self::constructor(state, Temporal::now().timestamp())
    }
}

#[async_trait]
impl APISpec<api::FlowAPI> for Flow {
    async fn run(&self) -> BoxResult<()>
        where
            Self: Sized + Sync,
    {
        let api = api::FlowAPI::default();
        println!("{}", &api);
        api.server()
            .await
            .ok()
            .unwrap()
            .await
            .expect("Server Error");
        Ok(())
    }
}

impl CLISpec<cli::FlowCLI> for Flow {
    fn run(&self) -> BoxResult<()>
        where
            Self: Sized,
    {
        let data = cli::FlowCLI::default();
        println!("{:#?}", data.action.clone());
        println!("{:#?}", data.command.clone());
        Ok(handle_cli_inputs(data))
    }
}

impl Default for Flow {
    fn default() -> Self {
        Self::new(AppState::default())
    }
}