serverless_workflow_core 1.0.0-alpha6

Contains Serverless Workflow DSL models
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
use std::collections::HashMap;
use serde_derive::{Deserialize, Serialize};
use crate::models::any::*;
use crate::models::duration::*;
use crate::models::event::*;
use crate::models::error::*;
use crate::models::map::*;
use crate::models::input::*;
use crate::models::resource::*;
use crate::models::retry::*;

/// Enumerates all supported task types
pub struct TaskType;
impl TaskType {
    /// Gets the type of a 'call' task
    pub const CALL: &'static str = "call";
    /// Gets the type of a 'do' task
    pub const DO: &'static str = "do";
    /// Gets the type of a 'emit' task
    pub const EMIT: &'static str = "emit";
    /// Gets the type of a 'for' task
    pub const FOR: &'static str = "for";
    /// Gets the type of a 'fork' task
    pub const FORK: &'static str = "fork";
    /// Gets the type of a 'listen' task
    pub const LISTEN: &'static str = "listen";
    /// Gets the type of a 'raise' task
    pub const RAISE: &'static str = "raise";
    /// Gets the type of a 'run' task
    pub const RUN: &'static str = "run";
    /// Gets the type of a 'set' task
    pub const SET: &'static str = "set";
    /// Gets the type of a 'switch' task
    pub const SWITCH: &'static str = "switch";
    /// Gets the type of a 'try' task
    pub const TRY: &'static str = "try";
    /// Gets the type of a 'wait' task
    pub const WAIT: &'static str = "wait";
}

/// Enumerates all supported process types
pub struct ProcessType;
impl ProcessType {
    /// Gets the type of a 'container' process
    pub const CONTAINER: &'static str = "container";
    /// Gets the type of a 'shell' process
    pub const SCRIPT: &'static str = "script";
    /// Gets the type of a 'shell' process
    pub const SHELL: &'static str = "shell";
    /// Gets the type of a 'workflow' process
    pub const WORKFLOW: &'static str = "workflow";
}

/// Represents a value that can be any of the supported task definitions
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TaskDefinition{
    /// Variant holding the definition of a 'call' task
    Call(CallTaskDefinition),
    /// Variant holding the definition of a 'do' task
    Do(DoTaskDefinition),
    /// Variant holding the definition of an 'emit' task
    Emit(EmitTaskDefinition),
    /// Variant holding the definition of a 'for' task
    For(ForTaskDefinition),
    /// Variant holding the definition of a 'fork' task
    Fork(ForkTaskDefinition),
    /// Variant holding the definition of a 'listen' task
    Listen(ListenTaskDefinition),
    /// Variant holding the definition of a 'raise' task
    Raise(RaiseTaskDefinition),
    /// Variant holding the definition of a 'run' task
    Run(RunTaskDefinition),
    /// Variant holding the definition of a 'set' task
    Set(SetTaskDefinition),
    /// Variant holding the definition of a 'switch' task
    Switch(SwitchTaskDefinition),
    /// Variant holding the definition of a 'try' task
    Try(TryTaskDefinition),
    /// Variant holding the definition of a 'wait' task
    Wait(WaitTaskDefinition)
}

/// A trait that all task definitions must implement
pub trait TypedTaskDefinition {
    /// Gets the task's type
    fn task_type(&self) -> &str;
}

/// Represents the definition of a task used to call a predefined function
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct CallTaskDefinition{

    /// Gets/sets the reference to the function to call
    #[serde(rename = "call")]
    pub call: String,

    /// Gets/sets a key/value mapping of the call's arguments, if any
    #[serde(rename = "with", skip_serializing_if = "Option::is_none")]
    pub with: Option<HashMap<String, AnyValue>>,

    /// Gets/sets a boolean indicating whether or not to wait for the called function to return. Defaults to true
    #[serde(rename = "await", skip_serializing_if = "Option::is_none")]
    pub await_: Option<bool>

}
impl TypedTaskDefinition for CallTaskDefinition {
    fn task_type(&self) -> &str {
        TaskType::CALL
    }
}
impl  CallTaskDefinition {
    pub fn new(call: &str, with: Option<HashMap<String, AnyValue>>, await_: Option<bool>) -> Self{
        Self { 
            call: call.to_string(), 
            with, 
            await_
        }
    }
}

/// Represents the configuration of a task that is composed of multiple subtasks to run sequentially
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct DoTaskDefinition{

    /// Gets/sets a name/definition mapping of the subtasks to perform sequentially
    #[serde(rename = "do")]
    pub do_: Map<String, TaskDefinition>

}
impl TypedTaskDefinition for DoTaskDefinition {
    fn task_type(&self) -> &str {
        TaskType::DO
    }
}
impl DoTaskDefinition {
    pub fn new(do_: Map<String, TaskDefinition>) -> Self{
        Self { 
            do_
        }
    }
}

/// Represents the configuration of a task used to emit an event
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct EmitTaskDefinition{

    /// Gets/sets the configuration of an event's emission
    #[serde(rename = "emit")]
    pub emit: EventEmissionDefinition

}
impl TypedTaskDefinition for EmitTaskDefinition {
    fn task_type(&self) -> &str {
        TaskType::EMIT
    }
}
impl EmitTaskDefinition {
    pub fn new(emit: EventEmissionDefinition) -> Self{
        Self { 
            emit 
        }
    }
}

/// Represents the configuration of an event's emission
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct EventEmissionDefinition{

    /// Gets/sets the definition of the event to emit
    #[serde(rename = "event")]
    pub event: EventDefinition

}
impl EventEmissionDefinition {
    pub fn new(event: EventDefinition) -> Self{
        Self { 
            event 
        }
    }
}

/// <summary>
/// Represents the definition of a task that executes a set of subtasks iteratively for each element in a collection
/// </summary>
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ForTaskDefinition{

    /// Gets/sets the definition of the loop that iterates over a range of values
    #[serde(rename = "for")]
    pub for_: ForLoopDefinition,

    /// Gets/sets a runtime expression that represents the condition, if any, that must be met for the iteration to continue
    #[serde(rename = "while", skip_serializing_if = "Option::is_none")]
    pub while_: Option<String>,

    /// Gets/sets the tasks to perform for each item in the collection
    #[serde(rename = "do")]
    pub do_: Map<String, TaskDefinition>

}
impl TypedTaskDefinition for ForTaskDefinition {
    fn task_type(&self) -> &str {
        TaskType::FOR
    }
}
impl ForTaskDefinition {
    pub fn new(for_: ForLoopDefinition, do_: Map<String, TaskDefinition>, while_: Option<String>) -> Self{
        Self { 
            for_, 
            while_, 
            do_
        }
    }
}

/// Represents the definition of a loop that iterates over a range of values
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ForLoopDefinition{

    /// Gets/sets the name of the variable that represents each element in the collection during iteration
    #[serde(rename = "emit")]
    pub each: String,

    /// Gets/sets the runtime expression used to get the collection to iterate over
    #[serde(rename = "in")]
    pub in_: String,

    /// Gets/sets the name of the variable used to hold the index of each element in the collection during iteration
    #[serde(rename = "at", skip_serializing_if = "Option::is_none")]
    pub at: Option<String>,

    /// Gets/sets the definition of the data, if any, to pass to iterations to run
    #[serde(rename = "input", skip_serializing_if = "Option::is_none")]
    pub input: Option<InputDataModelDefinition>,

}
impl ForLoopDefinition {
    pub fn new(each: &str, in_: &str, at: Option<String>, input: Option<InputDataModelDefinition>) -> Self{
        Self { 
            each: each.to_string(), 
            in_: in_.to_string(), 
            at, 
            input 
        }
    }
}

/// Represents the configuration of a task that is composed of multiple subtasks to run concurrently
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ForkTaskDefinition{

    /// Gets/sets the configuration of the branches to perform concurrently
    #[serde(rename = "fork")]
    pub fork: BranchingDefinition

}
impl TypedTaskDefinition for ForkTaskDefinition {
    fn task_type(&self) -> &str {
        TaskType::FORK
    }
}
impl ForkTaskDefinition {
    pub fn new(fork: BranchingDefinition) -> Self{
        Self { 
            fork
         }
    }
}

/// Represents an object used to configure branches to perform concurrently
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct BranchingDefinition{

    /// Gets/sets a name/definition mapping of the subtasks to perform concurrently
    #[serde(rename = "branches")]
    pub branches: Map<String, TaskDefinition>,

    /// Gets/sets a boolean indicating whether or not the branches should compete each other. If `true` and if a branch completes, it will cancel all other branches then it will return its output as the task's output
    #[serde(rename = "compete")]
    pub compete: bool

}
impl BranchingDefinition{
    pub fn new(branches:Map<String, TaskDefinition>, compete: bool) -> Self{
        Self { 
            branches, 
            compete 
        }
    }
}

/// Represents the configuration of a task used to listen to specific events
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ListenTaskDefinition{

    /// Gets/sets the configuration of the listener to use
    #[serde(rename = "listen")]
    pub listen: ListenerDefinition

}
impl TypedTaskDefinition for ListenTaskDefinition {
    fn task_type(&self) -> &str {
        TaskType::LISTEN
    }
}
impl ListenTaskDefinition {
    pub fn new(listen: ListenerDefinition) -> Self{
        Self { 
            listen
        }
    }
}

/// Represents the configuration of an event listener
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ListenerDefinition{

    /// Gets/sets the listener's target
    #[serde(rename = "to")]
    pub to: EventConsumptionStrategyDefinition

}
impl ListenerDefinition {
    pub fn new(to: EventConsumptionStrategyDefinition) -> Self{
        Self{
            to
        }
    }
}

/// Represents the configuration of a task used to listen to specific events
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct RaiseTaskDefinition{

    /// Gets/sets the definition of the error to raise
    #[serde(rename = "raise")]
    pub raise: RaiseErrorDefinition

}
impl TypedTaskDefinition for RaiseTaskDefinition {
    fn task_type(&self) -> &str {
        TaskType::RAISE
    }
}
impl RaiseTaskDefinition {
    pub fn new(raise: RaiseErrorDefinition) -> Self{
        Self{
            raise
        }
    }
}

/// Represents the definition of the error to raise
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct RaiseErrorDefinition{

    /// Gets/sets the error to raise
    #[serde(rename = "error")]
    pub error: OneOfErrorDefinitionOrReference

}
impl RaiseErrorDefinition{

    /// Initializes a new RaiseErrorDefinition
    pub fn new(error: OneOfErrorDefinitionOrReference) -> Self{
        Self { error }
    }

}

/// Represents the configuration of a task used to run a given process
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct RunTaskDefinition{

    /// Gets/sets the configuration of the process to execute
    #[serde(rename = "run")]
    pub run: ProcessTypeDefinition

}
impl TypedTaskDefinition for RunTaskDefinition {
    fn task_type(&self) -> &str {
        TaskType::RUN
    }
}
impl RunTaskDefinition {
    pub fn new(run: ProcessTypeDefinition) -> Self{
        Self { 
            run
        }
    }
}

/// Represents the configuration of a process execution
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ProcessTypeDefinition{

    /// Gets/sets the configuration of the container to run
    #[serde(rename = "container", skip_serializing_if = "Option::is_none")]
    pub container: Option<ContainerProcessDefinition>,

    /// Gets/sets the configuration of the script to run
    #[serde(rename = "script", skip_serializing_if = "Option::is_none")]
    pub script: Option<ScriptProcessDefinition>,

    /// Gets/sets the configuration of the shell command to run
    #[serde(rename = "shell", skip_serializing_if = "Option::is_none")]
    pub shell: Option<ShellProcessDefinition>,

    /// Gets/sets the configuration of the workflow to run
    #[serde(rename = "workflow", skip_serializing_if = "Option::is_none")]
    pub workflow: Option<WorkflowProcessDefinition>,

    /// Gets/sets a boolean indicating whether or not to await the process completion before continuing. Defaults to 'true'
    #[serde(rename = "await", skip_serializing_if = "Option::is_none")]
    pub await_: Option<bool>

}
impl ProcessTypeDefinition {

    /// Creates a new container process
    pub fn using_container(container: ContainerProcessDefinition, await_: Option<bool>) -> Self{
        Self { 
            container: Some(container),
            await_,
            shell: None,
            script: None,
            workflow: None
        }
    }

    /// Creates a new script process
    pub fn using_script(script: ScriptProcessDefinition, await_: Option<bool>) -> Self{
        Self { 
            script: Some(script),
            await_,
            container: None,
            shell: None,
            workflow: None
        }
    }

    /// Creates a new shell process
    pub fn using_shell(shell: ShellProcessDefinition, await_: Option<bool>) -> Self{
        Self { 
            shell: Some(shell),
            await_,
            container: None,
            script: None,
            workflow: None
        }
    }

    /// Creates a new workflow process
    pub fn using_workflow(workflow: WorkflowProcessDefinition, await_: Option<bool>) -> Self{
        Self { 
            workflow: Some(workflow),
            await_,
            container: None,
            shell: None,
            script: None
        }
    }
    
    /// Gets the type of the defined process
    pub fn get_process_type(&self) -> &str{
        if self.container.is_some(){
            ProcessType::CONTAINER
        }
        else if self.script.is_some(){
            ProcessType::SCRIPT
        }
        else if self.shell.is_some(){
            ProcessType::SHELL
        }
        else{
            ProcessType::WORKFLOW
        }
    }

}

/// Represents the configuration of a container process
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ContainerProcessDefinition{

    /// Gets/sets the name of the container image to run
    #[serde(rename = "image")]
    pub image: String,

    /// Gets/sets the name of the container to run
    #[serde(rename = "name")]
    pub name: Option<String>,

    /// Gets/sets the command, if any, to execute on the container
    #[serde(rename = "command", skip_serializing_if = "Option::is_none")]
    pub command: Option<String>,

    /// Gets/sets a list containing the container's port mappings, if any
    #[serde(rename = "ports", skip_serializing_if = "Option::is_none")]
    pub ports: Option<HashMap<u16, u16>>,

    /// Gets/sets the volume mapping for the container, if any
    #[serde(rename = "volumes", skip_serializing_if = "Option::is_none")]
    pub volumes: Option<HashMap<String, String>>,

    /// Gets/sets a key/value mapping of the environment variables, if any, to use when running the configured process
    #[serde(rename = "environment", skip_serializing_if = "Option::is_none")]
    pub environment: Option<HashMap<String, String>>,

}
impl ContainerProcessDefinition {
    pub fn new(image: &str, name: Option<String>, command: Option<String>, ports: Option<HashMap<u16, u16>>, volumes: Option<HashMap<String, String>>, environment: Option<HashMap<String, String>>) -> Self{
        Self { 
            image: image.to_string(), 
            name,
            command, 
            ports, 
            volumes, 
            environment
        }
    }
}

/// Represents the definition of a script evaluation process
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ScriptProcessDefinition{
    
    /// Gets/sets the language of the script to run
    #[serde(rename = "language")]
    pub language: String,

    /// Gets/sets the script's code. Required if 'source' has not been set
    #[serde(rename = "code", skip_serializing_if = "Option::is_none")]
    pub code: Option<String>,

    /// Gets the the script's source. Required if 'code' has not been set
    #[serde(rename = "source", skip_serializing_if = "Option::is_none")]
    pub source: Option<ExternalResourceDefinition>,

    /// Gets/sets a key/value mapping of the arguments, if any, to pass to the script to run
    #[serde(rename = "arguments", skip_serializing_if = "Option::is_none")]
    pub arguments: Option<HashMap<String, String>>,

    /// Gets/sets a key/value mapping of the environment variables, if any, to use when running the configured process
    #[serde(rename = "environment", skip_serializing_if = "Option::is_none")]
    pub environment: Option<HashMap<String, String>>,

}
impl ScriptProcessDefinition {

    /// Initializes a new script from code
    pub fn from_code(language: &str, code: String, arguments: Option<HashMap<String, String>>, environment: Option<HashMap<String, String>>) -> Self{
        Self { 
            language: language.to_string(), 
            code: Some(code), 
            source: None, 
            arguments, 
            environment
         }
    }

    /// Initializes a new script from an external resource
    pub fn from_source(language: &str, source: ExternalResourceDefinition, arguments: Option<HashMap<String, String>>, environment: Option<HashMap<String, String>>) -> Self{
        Self { 
            language: language.to_string(), 
            code: None, 
            source: Some(source), 
            arguments, 
            environment
         }
    }
}

/// Represents the definition of a shell process
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ShellProcessDefinition{
    
    /// Gets/sets the shell command to run
    #[serde(rename = "command")]
    pub command: String,

    /// Gets/sets the arguments of the shell command to run
    #[serde(rename = "arguments", skip_serializing_if = "Option::is_none")]
    pub arguments: Option<Vec<String>>,

    /// Gets/sets a key/value mapping of the environment variables, if any, to use when running the configured process
    #[serde(rename = "environment", skip_serializing_if = "Option::is_none")]
    pub environment: Option<HashMap<String, String>>,

}
impl ShellProcessDefinition {
    pub fn new(command: &str, arguments: Option<Vec<String>>, environment: Option<HashMap<String, String>>) -> Self{
        Self { 
            command: command.to_string(), 
            arguments, 
            environment
        }
    }
}

/// Represents the definition of a (sub)workflow process
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct WorkflowProcessDefinition{
    
    /// Gets/sets the namespace the workflow to run belongs to
    #[serde(rename = "namespace")]
    pub namespace: String,

    /// Gets/sets the name of the workflow to run
    #[serde(rename = "name")]
    pub name: String,

    /// Gets/sets the version of the workflow to run
    #[serde(rename = "version")]
    pub version: String,

    /// Gets/sets the data, if any, to pass as input to the workflow to execute. The value should be validated against the target workflow's input schema, if specified
    #[serde(rename = "input", skip_serializing_if = "Option::is_none")]
    pub input: Option<AnyValue>

}
impl WorkflowProcessDefinition {
    pub fn new(namespace: &str, name: &str, version: &str, input: Option<AnyValue>) -> Self{
        Self { 
            namespace: namespace.to_string(), 
            name: name.to_string(), 
            version: version.to_string(), 
            input
        }
    }
}

/// Represents the definition of a task used to set data
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct SetTaskDefinition{

    /// Gets/sets the data to set
    #[serde(rename = "set")]
    pub set: HashMap<String, AnyValue>

}
impl TypedTaskDefinition for SetTaskDefinition {
    fn task_type(&self) -> &str {
        TaskType::SET
    }
}
impl SetTaskDefinition {
    pub fn new() -> Self{
        Self { 
            set: HashMap::new()
        }
    }
}

/// Represents the definition of a task that evaluates conditions and executes specific branches based on the result
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct SwitchTaskDefinition{

    /// Gets/sets the definition of the switch to use
    #[serde(rename = "switch")]
    pub switch: Map<String, SwitchCaseDefinition>

}
impl TypedTaskDefinition for SwitchTaskDefinition {
    fn task_type(&self) -> &str {
        TaskType::SWITCH
    }
}
impl SwitchTaskDefinition {
    pub fn new() -> Self{
        Self { 
            switch: Map::new()
        }
    }
}

/// Represents the definition of a case within a switch task, defining a condition and corresponding tasks to execute if the condition is met
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct SwitchCaseDefinition{

    /// Gets/sets the condition that determines whether or not the case should be executed in a switch task
    #[serde(rename = "when", skip_serializing_if = "Option::is_none")]
    pub when: Option<String>,

    /// Gets/sets the transition to perform when the case matches
    #[serde(rename = "then", skip_serializing_if = "Option::is_none")]
    pub then: Option<String>

}

/// Represents the definition of a task used to try one or more subtasks, and to catch/handle the errors that can potentially be raised during execution
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct TryTaskDefinition{

    /// Gets/sets a name/definition map of the tasks to try running
    #[serde(rename = "try")]
    pub try_: Map<String, TaskDefinition>,

    /// Gets/sets the object used to define the errors to catch
    #[serde(rename = "catch")]
    pub catch: ErrorCatcherDefinition

}
impl TypedTaskDefinition for TryTaskDefinition {
    fn task_type(&self) -> &str {
        TaskType::TRY
    }
}
impl TryTaskDefinition {
    pub fn new(try_: Map<String, TaskDefinition>, catch: ErrorCatcherDefinition) -> Self{
        Self { 
            try_,
            catch
        }
    }
}

/// Represents the configuration of a concept used to catch errors
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ErrorCatcherDefinition{

    /// Gets/sets the definition of the errors to catch
    #[serde(rename = "errors", skip_serializing_if = "Option::is_none")]
    pub errors: Option<ErrorFilterDefinition>,

    /// Gets/sets the name of the runtime expression variable to save the error as. Defaults to 'error'.
    #[serde(rename = "as", skip_serializing_if = "Option::is_none")]
    pub as_: Option<String>,

    /// Gets/sets a runtime expression used to determine whether or not to catch the filtered error
    #[serde(rename = "when", skip_serializing_if = "Option::is_none")]
    pub when: Option<String>,

    /// Gets/sets a runtime expression used to determine whether or not to catch the filtered error
    #[serde(rename = "exceptWhen", skip_serializing_if = "Option::is_none")]
    pub except_when: Option<String>,

    /// Gets/sets the retry policy to use, if any
    #[serde(rename = "retry", skip_serializing_if = "Option::is_none")]
    pub retry: Option<OneOfRetryPolicyDefinitionOrReference>,

    /// Gets/sets a name/definition map of the tasks, if any, to run when catching an error
    #[serde(rename = "do", skip_serializing_if = "Option::is_none")]
    pub do_: Option<Map<String, TaskDefinition>>

}

/// Represents the definition an an error filter
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ErrorFilterDefinition{

    /// Gets/sets a key/value mapping of the properties errors to filter must define
    #[serde(rename = "with", skip_serializing_if = "Option::is_none")]
    pub with: Option<HashMap<String, AnyValue>>

}

/// Represents the definition of a task used to wait a certain amount of time
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct WaitTaskDefinition{

    /// Gets/sets the amount of time to wait before resuming workflow
    #[serde(rename = "duration")]
    pub duration: OneOfDurationOrIso8601Expression

}
impl TypedTaskDefinition for WaitTaskDefinition {
    fn task_type(&self) -> &str {
        TaskType::WAIT
    }
}
impl WaitTaskDefinition {
    pub fn new(duration: OneOfDurationOrIso8601Expression) -> Self{
        Self { 
            duration
        }
    }
}