1use crate::auth::AuthError;
18use crate::names::Name;
19use crate::sorting::SortField;
20use crate::timestamps::Timestamp;
21use serde::{Deserialize, Serialize};
22use strum_macros::IntoStaticStr;
23use thiserror::Error;
24use typed_builder::TypedBuilder;
25
26#[cfg(feature = "fp-bindgen")]
27use fp_bindgen::prelude::Serializable;
28
29#[cfg(feature = "axum_06")]
30use {
31 axum_06::http::StatusCode,
32 axum_06::response::{IntoResponse, Response},
33};
34
35#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, TypedBuilder)]
37#[non_exhaustive]
38#[serde(rename_all = "camelCase")]
39pub struct NewPagerDutyReceiver {
40 #[builder(default, setter())]
43 pub incident_created_template_name: Option<Name>,
44}
45
46#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, TypedBuilder)]
48#[non_exhaustive]
49#[serde(rename_all = "camelCase")]
50pub struct PagerDutyReceiver {
51 pub name: Name,
53
54 #[builder(default, setter())]
57 pub incident_created_template_name: Option<Name>,
58
59 pub security_key: String,
62
63 pub webhook_url: String,
65
66 #[builder(setter(into))]
68 pub created_at: Timestamp,
69
70 #[builder(setter(into))]
72 pub updated_at: Timestamp,
73}
74
75#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, TypedBuilder)]
76#[non_exhaustive]
77#[serde(rename_all = "camelCase")]
78pub struct UpdatePagerDutyReceiver {
79 #[builder(default, setter())]
82 #[serde(
83 default,
84 deserialize_with = "crate::deserialize_some",
85 skip_serializing_if = "Option::is_none"
86 )]
87 pub incident_created_template_name: Option<Option<Name>>,
88
89 #[builder(default, setter())]
92 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
93 pub regenerate_security_key: bool,
94}
95
96#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq, Error)]
98#[cfg_attr(
99 feature = "fp-bindgen",
100 derive(Serializable),
101 fp(rust_module = "fiberplane_models::pagerduty")
102)]
103#[non_exhaustive]
104#[serde(tag = "error", rename_all = "snake_case")]
105pub enum PagerDutyReceiverCreateError {
106 #[error("Name of the PagerDuty receiver is already in use")]
107 DuplicateName,
108
109 #[error("Referenced creation template does not exist")]
110 CreationTemplateNotFound,
111
112 #[error("Unknown error occurred")]
113 InternalServerError,
114
115 #[serde(untagged)]
117 #[error(transparent)]
118 Auth(AuthError),
119}
120
121impl From<AuthError> for PagerDutyReceiverCreateError {
122 fn from(value: AuthError) -> Self {
123 PagerDutyReceiverCreateError::Auth(value)
124 }
125}
126
127#[cfg(feature = "axum_06")]
128impl IntoResponse for PagerDutyReceiverCreateError {
129 fn into_response(self) -> Response {
130 let body = serde_json::to_string(&self).expect("should never fail!");
131 let status_code = match self {
132 PagerDutyReceiverCreateError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
133 PagerDutyReceiverCreateError::CreationTemplateNotFound => StatusCode::BAD_REQUEST,
134 PagerDutyReceiverCreateError::Auth(AuthError::Unauthenticated) => {
135 StatusCode::UNAUTHORIZED
136 }
137 PagerDutyReceiverCreateError::Auth(AuthError::Unauthorized) => StatusCode::FORBIDDEN,
138 PagerDutyReceiverCreateError::DuplicateName => StatusCode::BAD_REQUEST,
139 };
140
141 (status_code, body).into_response()
142 }
143}
144
145#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq, Error)]
147#[cfg_attr(
148 feature = "fp-bindgen",
149 derive(Serializable),
150 fp(rust_module = "fiberplane_models::pagerduty")
151)]
152#[non_exhaustive]
153#[serde(tag = "error", rename_all = "snake_case")]
154pub enum PagerDutyReceiverGetError {
155 #[error("PagerDuty receiver not found")]
156 NotFound,
157
158 #[error("Unknown error occurred")]
159 InternalServerError,
160
161 #[serde(untagged)]
163 #[error(transparent)]
164 Auth(AuthError),
165}
166
167impl From<AuthError> for PagerDutyReceiverGetError {
168 fn from(value: AuthError) -> Self {
169 PagerDutyReceiverGetError::Auth(value)
170 }
171}
172
173#[cfg(feature = "axum_06")]
174impl IntoResponse for PagerDutyReceiverGetError {
175 fn into_response(self) -> Response {
176 let body = serde_json::to_string(&self).expect("should never fail!");
177 let status_code = match self {
178 PagerDutyReceiverGetError::NotFound => StatusCode::NOT_FOUND,
179 PagerDutyReceiverGetError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
180 PagerDutyReceiverGetError::Auth(AuthError::Unauthenticated) => StatusCode::UNAUTHORIZED,
181 PagerDutyReceiverGetError::Auth(AuthError::Unauthorized) => StatusCode::FORBIDDEN,
182 };
183
184 (status_code, body).into_response()
185 }
186}
187
188#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq, Error)]
190#[cfg_attr(
191 feature = "fp-bindgen",
192 derive(Serializable),
193 fp(rust_module = "fiberplane_models::pagerduty")
194)]
195#[non_exhaustive]
196#[serde(tag = "error", rename_all = "snake_case")]
197pub enum PagerDutyReceiverUpdateError {
198 #[error("PagerDuty receiver not found")]
199 NotFound,
200
201 #[error("Referenced creation template does not exist")]
202 CreationTemplateNotFound,
203
204 #[error("Unknown error occurred")]
205 InternalServerError,
206
207 #[serde(untagged)]
209 #[error(transparent)]
210 Auth(AuthError),
211}
212
213impl From<AuthError> for PagerDutyReceiverUpdateError {
214 fn from(value: AuthError) -> Self {
215 PagerDutyReceiverUpdateError::Auth(value)
216 }
217}
218
219#[cfg(feature = "axum_06")]
220impl IntoResponse for PagerDutyReceiverUpdateError {
221 fn into_response(self) -> Response {
222 let body = serde_json::to_string(&self).expect("should never fail!");
223 let status_code = match self {
224 PagerDutyReceiverUpdateError::NotFound => StatusCode::NOT_FOUND,
225 PagerDutyReceiverUpdateError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
226 PagerDutyReceiverUpdateError::CreationTemplateNotFound => StatusCode::BAD_REQUEST,
227 PagerDutyReceiverUpdateError::Auth(AuthError::Unauthenticated) => {
228 StatusCode::UNAUTHORIZED
229 }
230 PagerDutyReceiverUpdateError::Auth(AuthError::Unauthorized) => StatusCode::FORBIDDEN,
231 };
232
233 (status_code, body).into_response()
234 }
235}
236
237#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq, Error)]
239#[cfg_attr(
240 feature = "fp-bindgen",
241 derive(Serializable),
242 fp(rust_module = "fiberplane_models::pagerduty")
243)]
244#[non_exhaustive]
245#[serde(tag = "error", rename_all = "snake_case")]
246pub enum PagerDutyReceiverDeleteError {
247 #[error("PagerDuty receiver not found")]
248 NotFound,
249
250 #[error("Unknown error occurred")]
251 InternalServerError,
252
253 #[serde(untagged)]
255 #[error(transparent)]
256 Auth(AuthError),
257}
258
259impl From<AuthError> for PagerDutyReceiverDeleteError {
260 fn from(value: AuthError) -> Self {
261 PagerDutyReceiverDeleteError::Auth(value)
262 }
263}
264
265#[cfg(feature = "axum_06")]
266impl IntoResponse for PagerDutyReceiverDeleteError {
267 fn into_response(self) -> Response {
268 let body = serde_json::to_string(&self).expect("should never fail!");
269 let status_code = match self {
270 PagerDutyReceiverDeleteError::NotFound => StatusCode::NOT_FOUND,
271 PagerDutyReceiverDeleteError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
272 PagerDutyReceiverDeleteError::Auth(AuthError::Unauthenticated) => {
273 StatusCode::UNAUTHORIZED
274 }
275 PagerDutyReceiverDeleteError::Auth(AuthError::Unauthorized) => StatusCode::FORBIDDEN,
276 };
277
278 (status_code, body).into_response()
279 }
280}
281
282#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq, Error)]
284#[cfg_attr(
285 feature = "fp-bindgen",
286 derive(Serializable),
287 fp(rust_module = "fiberplane_models::pagerduty")
288)]
289#[non_exhaustive]
290#[serde(tag = "error", rename_all = "snake_case")]
291pub enum PagerDutyReceiverListError {
292 #[error("Unknown error occurred")]
293 InternalServerError,
294
295 #[serde(untagged)]
297 #[error(transparent)]
298 Auth(AuthError),
299}
300
301impl From<AuthError> for PagerDutyReceiverListError {
302 fn from(value: AuthError) -> Self {
303 PagerDutyReceiverListError::Auth(value)
304 }
305}
306
307#[cfg(feature = "axum_06")]
308impl IntoResponse for PagerDutyReceiverListError {
309 fn into_response(self) -> Response {
310 let body = serde_json::to_string(&self).expect("should never fail!");
311 let status_code = match self {
312 PagerDutyReceiverListError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
313 PagerDutyReceiverListError::Auth(AuthError::Unauthenticated) => {
314 StatusCode::UNAUTHORIZED
315 }
316 PagerDutyReceiverListError::Auth(AuthError::Unauthorized) => StatusCode::FORBIDDEN,
317 };
318
319 (status_code, body).into_response()
320 }
321}
322
323#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq, IntoStaticStr)]
324#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
325#[cfg_attr(
326 feature = "fp-bindgen",
327 derive(Serializable),
328 fp(rust_module = "fiberplane_models::pagerduty")
329)]
330#[non_exhaustive]
331#[serde(rename_all = "snake_case")]
332#[strum(serialize_all = "snake_case")]
333pub enum PagerDutyReceiverListSortFields {
334 Name,
335 CreatedAt,
336 UpdatedAt,
337}
338
339impl SortField for PagerDutyReceiverListSortFields {
340 #[inline]
341 fn default_sort_field() -> Self {
342 Self::Name
343 }
344}