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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use serde::Deserialize;

pub mod backup;
pub mod logs;
pub mod manage;
pub mod status;

use crate::{Discloud, Error};

use self::{
    backup::AppBackup,
    logs::AppLogs,
    manage::{AppRamError, AppStartError, AppStartStatus, AppStopError},
    status::AppStatus,
};

#[derive(Deserialize, Debug, Clone)]
pub struct AppResponseAll {
    pub apps: Vec<App>,
    pub message: String,
    pub status: String,
}

#[derive(Deserialize, Debug, Clone)]
pub struct AppResponseUnique {
    pub apps: App,
    pub message: String,
    pub status: String,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct App {
    pub auto_deploy_git: String,
    pub auto_restart: bool,
    #[serde(rename = "avatarURL")]
    pub avatar_url: String,
    pub exit_code: i32,
    pub id: String,
    pub lang: String,
    pub main_file: String,
    pub mods: Vec<String>,
    pub name: String,
    pub online: bool,
    pub ram: i32,
    pub ram_killed: bool,
    pub r#type: i32,
}

impl App {
    pub async fn get_status(&self, client: &Discloud) -> Result<AppStatus, Error> {
        client.get_app_status(&self.id).await
    }

    pub async fn get_logs(&self, client: &Discloud) -> Result<AppLogs, Error> {
        client.get_app_logs(&self.id).await
    }

    pub async fn get_backup(&self, client: &Discloud) -> Result<AppBackup, Error> {
        client.get_app_backup(&self.id).await
    }

    pub async fn start(&self, client: &Discloud) -> Result<AppStartStatus, AppStartError> {
        client.start_app(&self.id).await
    }

    pub async fn stop(&self, client: &Discloud) -> Result<(), AppStopError> {
        client.stop_app(&self.id).await
    }

    pub async fn restart(&self, client: &Discloud) -> Result<(), Error> {
        client.restart_app(&self.id).await
    }

    pub async fn set_ram(&self, client: &Discloud, quantity: u32) -> Result<(), AppRamError> {
        client.set_app_ram(&self.id, quantity).await
    }

    pub async fn commit(&self) {
        todo!()
    }

    pub async fn delete(&self, client: &Discloud) -> Result<(), Error> {
        client.delete_app(&self.id).await
    }
}