Skip to main content

paperless_api/
workflow.rs

1//! Types related to paperless workflows.
2
3use std::collections::HashMap;
4
5use serde::Deserialize;
6use serde_repr::{Deserialize_repr, Serialize_repr};
7
8use paperless_api_macros::{Item, UpdateDto};
9
10/// A workflow.
11#[derive(Debug, Clone, Deserialize, Item, UpdateDto)]
12#[api_info(endpoint = "workflows")]
13pub struct Workflow {
14    /// Unique identifier of the workflow.
15    #[dto(skip)]
16    pub id: crate::id::WorkflowId,
17
18    /// Whether the workflow is enabled.
19    pub enabled: bool,
20
21    /// Name of the workflow.
22    pub name: String,
23
24    /// Order of the workflow in the list.
25    pub order: Option<i32>,
26
27    /// Triggers that determine when the workflow is executed.
28    #[dto(skip)] // TODO
29    pub triggers: Vec<WorkflowTrigger>,
30
31    /// Actions that are executed when the workflow is triggered.
32    #[dto(skip)] // TODO
33    pub actions: Vec<WorkflowAction>,
34}
35
36/// A trigger that determines when a workflow is executed.
37#[derive(Debug, Clone, Deserialize)]
38pub struct WorkflowTrigger {
39    /// Unique identifier of the trigger.
40    pub id: crate::id::WorkflowTriggerId,
41
42    /// The type of trigger.
43    #[serde(rename = "type")]
44    pub trigger_type: WorkflowTriggerType,
45}
46
47/// An action that can be executed when a workflow is triggered.
48#[derive(Debug, Clone, Deserialize)]
49pub struct WorkflowAction {
50    /// Unique identifier of the workflow action.
51    pub id: crate::id::WorkflowActionId,
52
53    /// The type of action.
54    #[serde(rename = "type")]
55    pub action_type: WorkflowActionType,
56
57    /// Webhook configuration, if the action type is a webhook.
58    pub webhook: Option<WebhookAction>,
59}
60
61/// The type of trigger that determines when a workflow is executed.
62#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
63#[repr(u8)]
64pub enum WorkflowTriggerType {
65    ProcessingStarted = 1,
66    DocumentAdded = 2,
67    DocumentUpdated = 3,
68    Scheduled = 4,
69}
70
71/// The type of action that is executed when a workflow is triggered.
72#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
73#[repr(u8)]
74pub enum WorkflowActionType {
75    Assign = 1,
76    Remove = 2,
77    Email = 3,
78    Webhook = 4,
79}
80
81/// A webhook action that can be executed when a workflow is triggered.
82#[derive(Debug, Clone, Deserialize)]
83pub struct WebhookAction {
84    /// Unique identifier of the webhook action.
85    pub id: crate::id::WebhookActionId,
86
87    /// URL of the webhook.
88    pub url: String,
89
90    /// Whether to use query parameters.
91    pub use_params: bool,
92
93    /// Whether to send the body as JSON.
94    pub as_json: bool,
95
96    /// Whether to include the document in the request.
97    pub include_document: bool,
98
99    /// Body of the webhook request.
100    pub body: Option<String>,
101
102    /// Headers to include in the webhook request.
103    pub headers: Option<HashMap<String, String>>,
104
105    /// Query parameters to include in the webhook request.
106    pub params: Option<HashMap<String, String>>,
107}