1#![allow(unused)]
2use serde::{Deserialize, Serialize, Deserializer};
3use std::collections::HashMap;
4use serde_json::value::Value;
5use std::fmt::Display;
6use super::*;
7
8#[derive(Debug, Serialize, Clone)]
9#[serde(deny_unknown_fields)]
10#[serde(untagged)]
11pub enum EmptyOption<T> {
12 Some(T),
13 None {},
14}
15
16impl<T> Display for EmptyOption<T>
17where
18 T: Display,
19{
20 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
21 match self {
22 EmptyOption::Some(t) => write!(f, "{}", t),
23 EmptyOption::None {} => write!(f, ""),
24 }
25 }
26}
27
28impl<'de, T> Deserialize<'de> for EmptyOption<T>
29where
30 T: Deserialize<'de>,
31{
32 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
33 where
34 D: Deserializer<'de>,
35 {
36 Option::deserialize(deserializer).map(Into::into)
37 }
38}
39
40impl<T> From<EmptyOption<T>> for Option<T> {
41 fn from(empty_option: EmptyOption<T>) -> Option<T> {
42 match empty_option {
43 EmptyOption::Some(option) => Some(option),
44 EmptyOption::None {} => None,
45 }
46 }
47}
48
49impl<T> From<Option<T>> for EmptyOption<T> {
50 fn from(option: Option<T>) -> EmptyOption<T> {
51 match option {
52 Some(option) => EmptyOption::Some(option),
53 None {} => EmptyOption::None {},
54 }
55 }
56}
57
58impl<T> EmptyOption<T> {
59 fn into_option(self) -> Option<T> {
60 self.into()
61 }
62 fn as_option(&self) -> Option<&T> {
63 match self {
64 EmptyOption::Some(option) => Some(option),
65 EmptyOption::None {} => None,
66 }
67 }
68}
69
70#[derive(Serialize, Deserialize, Debug, Clone)]
71pub struct Function {
72 #[serde(rename(serialize = "id", deserialize = "$id"))]
73 pub id: String,
74 pub execute: Vec<String>,
75 pub name: String,
76 pub dateCreated: i64,
77 pub dateUpdated: i64,
78 pub status: String,
79 pub runtime: String,
80 pub deployment: String,
81 pub vars: Option<HashMap<String, crate::client::ParamType>>,
82 pub events: Vec<String>,
83 pub schedule: String,
84 pub scheduleNext: i64,
85 pub schedulePrevious: i64,
86 pub timeout: i64,
87}
88
89impl Display for Function {
90 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
91 let mut formatBuffer = String::new();
92 formatBuffer.push_str(&format!("{:?}", self.id));
93 for item in &self.execute {
94 formatBuffer.push_str(&format!("{:?}", item));
95 }
96 formatBuffer.push_str(&format!("{:?}", self.name));
97 formatBuffer.push_str(&format!("{:?}", self.dateCreated));
98 formatBuffer.push_str(&format!("{:?}", self.dateUpdated));
99 formatBuffer.push_str(&format!("{:?}", self.status));
100 formatBuffer.push_str(&format!("{:?}", self.runtime));
101 formatBuffer.push_str(&format!("{:?}", self.deployment));
102 formatBuffer.push_str(&format!("{:?}", self.vars));
103 for item in &self.events {
104 formatBuffer.push_str(&format!("{:?}", item));
105 }
106 formatBuffer.push_str(&format!("{:?}", self.schedule));
107 formatBuffer.push_str(&format!("{:?}", self.scheduleNext));
108 formatBuffer.push_str(&format!("{:?}", self.schedulePrevious));
109 formatBuffer.push_str(&format!("{:?}", self.timeout));
110
111 write!(f, "{}", formatBuffer)
112 }
113}
114
115impl Function {
116 pub fn new(id: String, execute: Vec<String>, name: String, dateCreated: i64, dateUpdated: i64, status: String, runtime: String, deployment: String, vars: Option<HashMap<String, crate::client::ParamType>>, events: Vec<String>, schedule: String, scheduleNext: i64, schedulePrevious: i64, timeout: i64, ) -> Self {
117 Self {
118 id: id,
119 execute: execute,
120 name: name,
121 dateCreated: dateCreated,
122 dateUpdated: dateUpdated,
123 status: status,
124 runtime: runtime,
125 deployment: deployment,
126 vars: vars,
127 events: events,
128 schedule: schedule,
129 scheduleNext: scheduleNext,
130 schedulePrevious: schedulePrevious,
131 timeout: timeout,
132 }
133 }
134}