1use chrono::{DateTime, Utc};
2use std::path::PathBuf;
3
4#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
6pub enum CommandKind {
7 Put,
8 List,
9 Empty,
10 Restore,
11 Remove,
12}
13
14impl CommandKind {
15 pub fn as_str(&self) -> &'static str {
16 match self {
17 Self::Put => "put",
18 Self::List => "list",
19 Self::Empty => "empty",
20 Self::Restore => "restore",
21 Self::Remove => "rm",
22 }
23 }
24}
25
26impl std::fmt::Display for CommandKind {
27 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28 write!(f, "{}", self.as_str())
29 }
30}
31
32#[derive(Debug, Clone)]
34pub struct CommandContext {
35 pub command: CommandKind,
36 pub args: Vec<String>,
37 pub cwd: PathBuf,
38 pub interactive: bool,
39 pub dry_run: bool,
40}
41
42#[derive(Debug, Clone)]
43pub struct CommandOutput {
44 pub command: CommandKind,
45 pub stdout: Vec<String>,
46 pub stderr: Vec<String>,
47 pub exit_code: u8,
48}
49
50impl CommandOutput {
51 pub fn success(command: CommandKind, stdout: impl Into<Vec<String>>) -> Self {
52 Self {
53 command,
54 stdout: stdout.into(),
55 stderr: Vec::new(),
56 exit_code: 0,
57 }
58 }
59
60 pub fn with_error(command: CommandKind, stderr: impl Into<String>) -> Self {
61 Self {
62 command,
63 stdout: Vec::new(),
64 stderr: vec![stderr.into()],
65 exit_code: 1,
66 }
67 }
68}
69
70#[derive(Debug, Clone)]
71pub struct TrashDirectory {
72 pub path: PathBuf,
73 pub files_dir: PathBuf,
74 pub info_dir: PathBuf,
75 pub mount_point: Option<PathBuf>,
76}
77
78impl TrashDirectory {
79 pub fn new(path: PathBuf, files_dir: PathBuf, info_dir: PathBuf) -> Self {
80 Self {
81 path,
82 files_dir,
83 info_dir,
84 mount_point: None,
85 }
86 }
87
88 pub fn with_mount_point(mut self, mount_point: PathBuf) -> Self {
89 self.mount_point = Some(mount_point);
90 self
91 }
92}
93
94#[derive(Debug, Clone)]
95pub struct TrashedItem {
96 pub original_path: PathBuf,
97 pub trashed_path: PathBuf,
98 pub info_path: PathBuf,
99 pub trash_dir: PathBuf,
100 pub size_bytes: Option<u64>,
101 pub deleted_at: Option<DateTime<Utc>>,
102}
103
104impl TrashedItem {
105 pub fn new(original_path: PathBuf, trashed_path: PathBuf, info_path: PathBuf, trash_dir: PathBuf) -> Self {
106 Self {
107 original_path,
108 trashed_path,
109 info_path,
110 trash_dir,
111 size_bytes: None,
112 deleted_at: None,
113 }
114 }
115}
116
117#[derive(Debug, Clone)]
118pub struct TrashCommand {
119 pub kind: CommandKind,
120 pub context: CommandContext,
121 pub request_id: Option<String>,
122}
123
124#[derive(Debug, Clone)]
125pub enum SkipReason {
126 MissingPath(PathBuf),
127 AlreadyTrashed(PathBuf),
128 UnsupportedScheme(String),
129 InternalError(String),
130}
131
132#[derive(Debug, Clone)]
133pub enum CommandOutcome {
134 Completed(CommandOutput),
135 Skipped {
136 command: CommandKind,
137 path: PathBuf,
138 reason: SkipReason,
139 },
140 Failed {
141 command: CommandKind,
142 reason: String,
143 },
144}
145
146#[derive(Debug, Clone, Copy)]
147pub enum ExitStatusLike {
148 Ok,
149 Warning,
150 Error,
151}
152
153impl ExitStatusLike {
154 pub fn as_code(self) -> u8 {
155 match self {
156 Self::Ok => 0,
157 Self::Warning => 2,
158 Self::Error => 1,
159 }
160 }
161}