1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
8#[serde(rename_all = "lowercase")]
9pub enum ContainerStatus {
10 Running,
11 Stopped,
12 Creating,
13 Error,
14 #[serde(other)]
15 Unknown,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct Container {
21 pub id: String,
23 #[serde(default)]
25 pub name: String,
26 #[serde(default)]
28 pub image: String,
29 #[serde(default)]
31 pub status: String,
32 #[serde(default)]
34 pub created_at: String,
35 #[serde(default)]
37 pub started_at: Option<String>,
38 #[serde(default)]
40 pub labels: HashMap<String, String>,
41 #[serde(default)]
43 pub environment: HashMap<String, String>,
44}
45
46#[derive(Debug, Clone, Serialize, Default)]
48pub struct CreateContainerRequest {
49 pub image: String,
51 #[serde(skip_serializing_if = "Option::is_none")]
53 pub name: Option<String>,
54 #[serde(skip_serializing_if = "HashMap::is_empty", default)]
56 pub environment: HashMap<String, String>,
57 #[serde(skip_serializing_if = "HashMap::is_empty", default)]
59 pub labels: HashMap<String, String>,
60}
61
62impl CreateContainerRequest {
63 pub fn new(image: impl Into<String>) -> Self {
65 Self {
66 image: image.into(),
67 ..Default::default()
68 }
69 }
70
71 pub fn name(mut self, name: impl Into<String>) -> Self {
73 self.name = Some(name.into());
74 self
75 }
76
77 pub fn env(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
79 self.environment.insert(key.into(), value.into());
80 self
81 }
82
83 pub fn label(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
85 self.labels.insert(key.into(), value.into());
86 self
87 }
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct FileInfo {
93 pub name: String,
95 pub path: String,
97 pub size: u64,
99 pub mode: String,
101 pub mod_time: String,
103 pub is_dir: bool,
105}
106
107#[derive(Debug, Clone, Serialize)]
109pub struct ResizeMessage {
110 #[serde(rename = "type")]
111 pub msg_type: String,
112 pub cols: u16,
113 pub rows: u16,
114}
115
116impl ResizeMessage {
117 pub fn new(cols: u16, rows: u16) -> Self {
118 Self {
119 msg_type: "resize".into(),
120 cols,
121 rows,
122 }
123 }
124}