plansolve 0.27.0

Official Rust client library for the PlanSolve optimization API.
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
use serde::{Deserialize, Serialize};

/// Request model for starting a shift optimization.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ShiftRequest {
    /// Optional caller-supplied identifier for the plan.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,
    /// Plan display name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Free-text plan description.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// Contracts defining the working-time rules referenced by employees.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub contracts: Vec<Contract>,
    /// Shifts that need to be staffed.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub shifts: Vec<ShiftAssignment>,
    /// Employees available to be assigned to shifts.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub employees: Vec<ShiftEmployee>,
    /// Optional controls governing how the shift solver runs.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub options: Option<Options>,
    /// Per-constraint penalty weights that steer the solver's objective.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub weights: Option<Weights>,
    /// Fairness configuration.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub fairness: Option<Fairness>,
    /// Employee requests to have specific days off.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub day_off_requests: Vec<DayOffRequest>,
    /// Employee requests to avoid specific shifts.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub shift_off_requests: Vec<ShiftOffRequest>,
    /// Optional callback URL invoked when solving completes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub hook: Option<String>,
    /// Advanced knobs for the shift constraint set.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub constraint_weight_overrides: Option<ConstraintWeightOverrides>,
}

/// A time window for shift scheduling.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Shift {
    /// Caller-supplied unique identifier for the shift.
    pub id: String,
    /// Earliest the shift may start.
    pub min_start_time: String,
    /// Latest the shift may end.
    pub max_end_time: String,
}

/// A shift assignment to be scheduled.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ShiftAssignment {
    /// Shift name, used as its identifier.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Shift start, as an ISO-8601 timestamp.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from: Option<String>,
    /// Shift end, as an ISO-8601 timestamp.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub to: Option<String>,
    /// Skills an employee must have to be assigned this shift.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub skills: Vec<String>,
    /// Cost of staffing this shift.
    #[serde(default)]
    pub cost: f64,
    /// Business value of staffing this shift.
    #[serde(default)]
    pub value: i64,
    /// Relative priority of staffing this shift.
    #[serde(default)]
    pub priority: i64,
    /// Skills that are preferred but not required.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub desired_skills: Vec<String>,
    /// Arbitrary tags used for grouping and affinity constraints.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub tags: Vec<String>,
    /// When true, the existing assignment is locked and left unchanged by the solver.
    #[serde(default)]
    pub pinned_by_user: bool,
}

/// An employee in the shift optimization.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ShiftEmployee {
    /// Employee name, used as the identifier referenced by requests and assignments.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Name of the [`Contract`] governing this employee's working-time rules.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub contract: Option<String>,
    /// Skills the employee possesses.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub skills: Vec<String>,
    /// Date the employee last had rest.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_rest_date: Option<String>,
    /// Dates/periods the employee is available to work.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub availability: Vec<String>,
    /// Shifts/periods the employee prefers to work.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub preference: Vec<String>,
    /// Period-specific working-time rules for this employee.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub period_rules: Vec<PeriodRule>,
    /// Dates the employee cannot work.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub unavailable_dates: Vec<String>,
    /// Arbitrary tags used for grouping and affinity constraints.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub tags: Vec<String>,
    /// Cap on weekly working minutes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub maximum_minutes_per_week: Option<i64>,
    /// Solution: shifts assigned to this employee.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub shifts: Vec<ShiftAssignment>,
}

/// A shift employee contract.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Contract {
    /// Contract name, referenced by an employee's `contract` field.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Maximum total working time, as an ISO-8601 duration.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max: Option<String>,
    /// Minimum total working time, as an ISO-8601 duration.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min: Option<String>,
    /// Maximum consecutive days that may be worked.
    #[serde(default)]
    pub max_consecutive_work_days: i64,
    /// Maximum shifts allowed on a single day.
    #[serde(default)]
    pub max_shifts_day: i64,
    /// Minimum rest between two shifts on the same day.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_rest_between_shifts_same_day: Option<String>,
    /// Maximum working days in the planning period.
    #[serde(default)]
    pub max_working_days: i64,
    /// Latest permitted shift start time.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub latest_shift_start: Option<String>,
    /// Earliest permitted shift start time.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub earliest_shift_start: Option<String>,
    /// Minimum consecutive days off between working stretches.
    #[serde(default)]
    pub minimum_consecutive_days_off: i64,
    /// Minimum hours off between consecutive shifts.
    #[serde(default)]
    pub minimum_hours_off_between_shifts: i64,
}

/// Constraint weights for the shift optimizer.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Weights {
    /// Penalty for assigning an employee who lacks a shift's required skills.
    pub required_skills: i64,
    /// Penalty for exceeding a shift's staffing capacity.
    pub shift_capacity: i64,
    /// Penalty for staffing a shift below its minimum required headcount.
    pub minimum_staffing: i64,
    /// Penalty for assigning an employee to overlapping shifts.
    pub no_double_booking: i64,
    /// Penalty for violating the required rest between consecutive shifts.
    pub rest_between_shifts: i64,
    /// Penalty for assigning an employee outside their declared availability.
    pub employee_availability: i64,
    /// Reward/penalty weight for honoring employees' shift preferences.
    pub shift_preferences: i64,
    /// Weight for minimizing total staffing cost.
    pub cost_minimization: i64,
    /// Weight for balancing workload evenly across employees.
    pub workload_balance: i64,
    /// Weight for the fairness objective across fairness buckets.
    pub fairness: i64,
    /// Penalty for exceeding the maximum consecutive working days.
    pub max_consecutive_work_days: i64,
    /// Penalty for exceeding the maximum shifts per day.
    pub max_shifts_per_day: i64,
    /// Penalty for exceeding the maximum working days per week.
    pub max_working_days_per_week: i64,
    /// Penalty for violating the contract's minimum rest between shifts.
    pub contract_rest_between_shifts: i64,
    /// Penalty for starting a shift before the contract's earliest allowed start.
    pub earliest_shift_start: i64,
    /// Penalty for starting a shift after the contract's latest allowed start.
    pub latest_shift_start: i64,
    /// Penalty for providing fewer than the minimum consecutive days off.
    pub minimum_consecutive_days_off: i64,
    /// Penalty for violating an employee's period-specific rule.
    pub period_rule_violation: i64,
    /// Weight for preferring employees who hold a shift's desired skills.
    pub desired_skills: i64,
    /// Weight for honoring employees' desired day-off requests.
    pub desired_day_off: i64,
    /// Weight for honoring employees' shift-off requests.
    pub shift_off_request: i64,
    /// Weight for balancing total time worked across employees.
    pub balance_time_worked: i64,
    /// Weight for keeping tagged employees working together.
    pub employee_affinity: i64,
    /// Weight for avoiding shifts scheduled immediately adjacent to a day off.
    pub avoid_shift_close_to_day_off: i64,
}

/// Solver options for the shift optimizer.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Options {
    /// When true, keeps existing assignments and only fills the gaps.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub partial_planning: Option<bool>,
    /// Maximum number of solver iterations before stopping.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_iterations: Option<i64>,
    /// Maximum solve time in seconds.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub time_limit: Option<i64>,
}

/// Fairness configuration for the shift optimizer.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Fairness {
    /// Buckets defining the groups the fairness objective balances over.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub fairness_buckets: Vec<FairnessBucket>,
}

/// A fairness bucket grouping employees and shifts.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FairnessBucket {
    /// Name identifier for the fairness bucket.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// List of employee names in this bucket.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub employees: Vec<String>,
    /// List of shift names in this bucket.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub shifts: Vec<String>,
    /// Time period for this bucket (e.g. `2024-01-01/2024-01-08`).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub period: Option<String>,
}

/// An employee's request for a day off.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DayOffRequest {
    /// Optional caller-supplied identifier for the request.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,
    /// Name of the employee making the request.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub employee_name: Option<String>,
    /// The requested day off, as an ISO-8601 date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub date: Option<String>,
    /// Strength of the preference; higher values make honoring it more important.
    #[serde(default)]
    pub weight: i64,
}

/// An employee's request to be off a specific shift.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ShiftOffRequest {
    /// Optional caller-supplied identifier.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,
    /// Name of the employee making the request.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub employee_name: Option<String>,
    /// Name of the shift the employee wants to avoid.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub shift_name: Option<String>,
    /// Strength of the preference; higher values make honoring it more important.
    #[serde(default)]
    pub weight: i64,
}

/// A period-based working constraint.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PeriodRule {
    /// The planning period this rule applies to.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub period: Option<PlanningPeriod>,
    /// Maximum working days allowed within the period.
    #[serde(default)]
    pub max_working_days: i64,
    /// Minimum working days required within the period.
    #[serde(default)]
    pub min_working_days: i64,
    /// Minimum total working time within the period.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_working_duration: Option<String>,
    /// Maximum total working time within the period.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_working_duration: Option<String>,
    /// Minimum rest between shifts on the same day.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_rest_duration_between_shifts_same_day: Option<String>,
    /// Minimum rest between consecutive shifts.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_rest_duration: Option<String>,
}

/// A time period for planning rules.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PlanningPeriod {
    /// Start of the period.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from: Option<String>,
    /// End of the period.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub to: Option<String>,
}

/// Overrides for constraint weights.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConstraintWeightOverrides {
    /// Names of constraints the solver is expected to recognize and apply.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub known_constraint_names: Vec<String>,
}

/// Response from starting a shift optimization.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ShiftStartResponse {
    /// Public PlanSolve job identifier - use it to poll status and fetch the solution.
    pub job_id: String,
    /// The underlying solver engine's job identifier, when exposed.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub solver_job_id: Option<String>,
    /// Inline solver result as raw JSON, when available synchronously.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub result: Option<String>,
    /// Error message when the solve request could not be accepted or run.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
}

/// Response from getting shift optimization results.
///
/// The server returns a full echo of the request (all planning inputs) plus the
/// result fields `feasible`, `scoreString`, `score`, `unassignedShifts`, and
/// `assignedShifts`. The wire body carries **no** `jobId`; `job_id` here is a
/// client-side convenience stamped by
/// [`ShiftClient::get_result`](crate::shift::ShiftClient::get_result) and is never
/// read from or written to the wire.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ShiftResultResponse {
    /// Public PlanSolve job identifier, stamped client-side from the request.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub job_id: Option<String>,
    // Echoed request fields.
    /// Echoed plan identifier.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,
    /// Echoed plan display name.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Echoed plan description.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// Echoed contracts defining the working-time rules referenced by employees.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub contracts: Vec<Contract>,
    /// Echoed shifts that needed to be staffed.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub shifts: Vec<ShiftAssignment>,
    /// Employees with their assigned shifts populated by the solver.
    #[serde(default)]
    pub employees: Vec<ShiftEmployee>,
    /// Echoed employee day-off requests.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub day_off_requests: Vec<DayOffRequest>,
    /// Echoed employee shift-off requests.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub shift_off_requests: Vec<ShiftOffRequest>,
    /// Echoed solver options.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub options: Option<Options>,
    /// Echoed per-constraint penalty weights.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub weights: Option<Weights>,
    /// Echoed fairness configuration.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fairness: Option<Fairness>,
    /// Echoed callback URL invoked when solving completes.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub hook: Option<String>,
    /// Echoed advanced knobs for the shift constraint set.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub constraint_weight_overrides: Option<ConstraintWeightOverrides>,
    // Result fields.
    /// Whether the returned solution satisfies all hard constraints.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub feasible: Option<bool>,
    /// Final score as a solver score string.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub score_string: Option<String>,
    /// Score broken down into its component levels.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub score: Option<serde_json::Value>,
    /// Shifts the solver could not staff.
    #[serde(default)]
    pub unassigned_shifts: Vec<ShiftAssignment>,
    /// Shifts the solver successfully staffed.
    #[serde(default)]
    pub assigned_shifts: Vec<ShiftAssignment>,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn serializes_and_omits_empty_collections() {
        let json = serde_json::to_string(&ShiftRequest::default()).unwrap();
        // Empty optional vectors are omitted, keeping payloads lean.
        assert!(!json.contains("\"shifts\""));
        assert!(!json.contains("\"employees\""));
    }

    #[test]
    fn serializes_populated_assignment() {
        let request = ShiftRequest {
            shifts: vec![ShiftAssignment {
                name: Some("Night".into()),
                cost: 12.5,
                priority: 3,
                pinned_by_user: true,
                ..Default::default()
            }],
            ..Default::default()
        };
        let json = serde_json::to_string(&request).unwrap();
        assert!(json.contains("\"shifts\""));
        assert!(json.contains("\"pinnedByUser\":true"));
        assert!(json.contains("\"cost\":12.5"));
    }

    #[test]
    fn request_omits_result_only_fields() {
        // score / assignedShifts / unassignedShifts belong to the response, never the
        // request — a fully-defaulted request must not emit them.
        let json = serde_json::to_string(&ShiftRequest::default()).unwrap();
        assert!(!json.contains("\"score\""));
        assert!(!json.contains("\"assignedShifts\""));
        assert!(!json.contains("\"unassignedShifts\""));
    }

    #[test]
    fn deserializes_result_response() {
        // The response is a full echo of the request plus the result fields.
        let json = r#"{
            "id": "roster-1",
            "name": "January roster",
            "description": "night ward",
            "contracts": [{"name": "full-time", "max": "PT40H"}],
            "shifts": [
                {"name": "Ward A", "from": "2024-01-15T22:00:00", "to": "2024-01-16T06:00:00"}
            ],
            "dayOffRequests": [{"employeeName": "Alice", "date": "2024-01-20", "weight": 5}],
            "shiftOffRequests": [{"employeeName": "Alice", "shiftName": "Ward B", "weight": 3}],
            "options": {"partialPlanning": true},
            "hook": "https://example.test/hook",
            "feasible": true,
            "scoreString": "0hard/0medium/-45soft",
            "score": {"hard": 0, "medium": 0, "soft": -45},
            "assignedShifts": [
                {"name": "Ward A", "from": "2024-01-15T22:00:00", "to": "2024-01-16T06:00:00",
                 "skills": ["nurse"], "cost": 12.5, "value": 2, "priority": 3}
            ],
            "unassignedShifts": [
                {"name": "Ward B", "from": "2024-01-16T22:00:00", "to": "2024-01-17T06:00:00",
                 "skills": ["nurse", "first_aid"]}
            ],
            "employees": [
                {"name": "Alice", "skills": ["nurse"], "shifts": [
                    {"name": "Ward A", "from": "2024-01-15T22:00:00", "to": "2024-01-16T06:00:00"}
                ]}
            ]
        }"#;

        let result: ShiftResultResponse = serde_json::from_str(json).unwrap();
        // Echoed request fields.
        assert_eq!(result.id.as_deref(), Some("roster-1"));
        assert_eq!(result.name.as_deref(), Some("January roster"));
        assert_eq!(result.contracts.len(), 1);
        assert_eq!(result.shifts.len(), 1);
        assert_eq!(result.day_off_requests.len(), 1);
        assert_eq!(result.shift_off_requests.len(), 1);
        assert_eq!(
            result.options.as_ref().unwrap().partial_planning,
            Some(true)
        );
        assert_eq!(result.hook.as_deref(), Some("https://example.test/hook"));
        // Result fields.
        assert_eq!(result.feasible, Some(true));
        assert_eq!(
            result.score_string.as_deref(),
            Some("0hard/0medium/-45soft")
        );
        assert_eq!(result.assigned_shifts.len(), 1);
        assert_eq!(result.assigned_shifts[0].name.as_deref(), Some("Ward A"));
        assert_eq!(
            result.assigned_shifts[0].from.as_deref(),
            Some("2024-01-15T22:00:00")
        );
        assert_eq!(result.assigned_shifts[0].cost, 12.5);
        assert_eq!(result.unassigned_shifts.len(), 1);
        assert_eq!(result.employees.len(), 1);
        assert_eq!(result.employees[0].shifts.len(), 1);
    }
}