ocppsim 0.1.0

A terminal OCPP-J charge point simulator.
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
use crate::ocpp::OcppVersion;

#[cfg_attr(not(test), allow(dead_code))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum EmbeddedSchemaType {
  Request,
  Response,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct EmbeddedSchema {
  pub(crate) action: &'static str,
  pub(crate) file_name: &'static str,
  pub(crate) relative_path: &'static str,
  pub(crate) text: &'static str,
}

macro_rules! embedded_schema {
  ($version:literal, $file_name:expr, $action:literal) => {
    EmbeddedSchema {
      action: $action,
      file_name: $file_name,
      relative_path: concat!("schemas/", $version, "/", $file_name),
      text: include_str!(concat!("../schemas/", $version, "/", $file_name)),
    }
  };
}

macro_rules! v1_6_request_schema {
  ($action:literal) => {
    embedded_schema!("1.6", concat!($action, ".json"), $action)
  };
}

macro_rules! v1_6_response_schema {
  ($action:literal) => {
    embedded_schema!("1.6", concat!($action, "Response.json"), $action)
  };
}

macro_rules! v2_x_request_schema {
  ($version:literal, $action:literal) => {
    embedded_schema!($version, concat!($action, "Request.json"), $action)
  };
  ($version:literal, $action:literal, $file_name:literal) => {
    embedded_schema!($version, $file_name, $action)
  };
}

macro_rules! v2_x_response_schema {
  ($version:literal, $action:literal) => {
    embedded_schema!($version, concat!($action, "Response.json"), $action)
  };
}

const V1_6_REQUEST_SCHEMAS: &[EmbeddedSchema] = &[
  v1_6_request_schema!("Authorize"),
  v1_6_request_schema!("BootNotification"),
  v1_6_request_schema!("CancelReservation"),
  v1_6_request_schema!("ChangeAvailability"),
  v1_6_request_schema!("ChangeConfiguration"),
  v1_6_request_schema!("ClearCache"),
  v1_6_request_schema!("ClearChargingProfile"),
  v1_6_request_schema!("DataTransfer"),
  v1_6_request_schema!("DiagnosticsStatusNotification"),
  v1_6_request_schema!("FirmwareStatusNotification"),
  v1_6_request_schema!("GetCompositeSchedule"),
  v1_6_request_schema!("GetConfiguration"),
  v1_6_request_schema!("GetDiagnostics"),
  v1_6_request_schema!("GetLocalListVersion"),
  v1_6_request_schema!("Heartbeat"),
  v1_6_request_schema!("MeterValues"),
  v1_6_request_schema!("RemoteStartTransaction"),
  v1_6_request_schema!("RemoteStopTransaction"),
  v1_6_request_schema!("ReserveNow"),
  v1_6_request_schema!("Reset"),
  v1_6_request_schema!("SendLocalList"),
  v1_6_request_schema!("SetChargingProfile"),
  v1_6_request_schema!("StartTransaction"),
  v1_6_request_schema!("StatusNotification"),
  v1_6_request_schema!("StopTransaction"),
  v1_6_request_schema!("TriggerMessage"),
  v1_6_request_schema!("UnlockConnector"),
  v1_6_request_schema!("UpdateFirmware"),
];

const V1_6_RESPONSE_SCHEMAS: &[EmbeddedSchema] = &[
  v1_6_response_schema!("Authorize"),
  v1_6_response_schema!("BootNotification"),
  v1_6_response_schema!("CancelReservation"),
  v1_6_response_schema!("ChangeAvailability"),
  v1_6_response_schema!("ChangeConfiguration"),
  v1_6_response_schema!("ClearCache"),
  v1_6_response_schema!("ClearChargingProfile"),
  v1_6_response_schema!("DataTransfer"),
  v1_6_response_schema!("DiagnosticsStatusNotification"),
  v1_6_response_schema!("FirmwareStatusNotification"),
  v1_6_response_schema!("GetCompositeSchedule"),
  v1_6_response_schema!("GetConfiguration"),
  v1_6_response_schema!("GetDiagnostics"),
  v1_6_response_schema!("GetLocalListVersion"),
  v1_6_response_schema!("Heartbeat"),
  v1_6_response_schema!("MeterValues"),
  v1_6_response_schema!("RemoteStartTransaction"),
  v1_6_response_schema!("RemoteStopTransaction"),
  v1_6_response_schema!("ReserveNow"),
  v1_6_response_schema!("Reset"),
  v1_6_response_schema!("SendLocalList"),
  v1_6_response_schema!("SetChargingProfile"),
  v1_6_response_schema!("StartTransaction"),
  v1_6_response_schema!("StatusNotification"),
  v1_6_response_schema!("StopTransaction"),
  v1_6_response_schema!("TriggerMessage"),
  v1_6_response_schema!("UnlockConnector"),
  v1_6_response_schema!("UpdateFirmware"),
];

const V2_0_1_REQUEST_SCHEMAS: &[EmbeddedSchema] = &[
  v2_x_request_schema!("2.0.1", "Authorize"),
  v2_x_request_schema!("2.0.1", "BootNotification"),
  v2_x_request_schema!("2.0.1", "CancelReservation"),
  v2_x_request_schema!("2.0.1", "CertificateSigned"),
  v2_x_request_schema!("2.0.1", "ChangeAvailability"),
  v2_x_request_schema!("2.0.1", "ClearCache"),
  v2_x_request_schema!("2.0.1", "ClearChargingProfile"),
  v2_x_request_schema!("2.0.1", "ClearDisplayMessage"),
  v2_x_request_schema!("2.0.1", "ClearVariableMonitoring"),
  v2_x_request_schema!("2.0.1", "ClearedChargingLimit"),
  v2_x_request_schema!("2.0.1", "CostUpdated"),
  v2_x_request_schema!("2.0.1", "CustomerInformation"),
  v2_x_request_schema!("2.0.1", "DataTransfer"),
  v2_x_request_schema!("2.0.1", "DeleteCertificate"),
  v2_x_request_schema!("2.0.1", "FirmwareStatusNotification"),
  v2_x_request_schema!("2.0.1", "Get15118EVCertificate"),
  v2_x_request_schema!("2.0.1", "GetBaseReport"),
  v2_x_request_schema!("2.0.1", "GetCertificateStatus"),
  v2_x_request_schema!("2.0.1", "GetChargingProfiles"),
  v2_x_request_schema!("2.0.1", "GetCompositeSchedule"),
  v2_x_request_schema!("2.0.1", "GetDisplayMessages"),
  v2_x_request_schema!("2.0.1", "GetInstalledCertificateIds"),
  v2_x_request_schema!("2.0.1", "GetLocalListVersion"),
  v2_x_request_schema!("2.0.1", "GetLog"),
  v2_x_request_schema!("2.0.1", "GetMonitoringReport"),
  v2_x_request_schema!("2.0.1", "GetReport"),
  v2_x_request_schema!("2.0.1", "GetTransactionStatus"),
  v2_x_request_schema!("2.0.1", "GetVariables"),
  v2_x_request_schema!("2.0.1", "Heartbeat"),
  v2_x_request_schema!("2.0.1", "InstallCertificate"),
  v2_x_request_schema!("2.0.1", "LogStatusNotification"),
  v2_x_request_schema!("2.0.1", "MeterValues"),
  v2_x_request_schema!("2.0.1", "NotifyChargingLimit"),
  v2_x_request_schema!("2.0.1", "NotifyCustomerInformation"),
  v2_x_request_schema!("2.0.1", "NotifyDisplayMessages"),
  v2_x_request_schema!("2.0.1", "NotifyEVChargingNeeds"),
  v2_x_request_schema!("2.0.1", "NotifyEVChargingSchedule"),
  v2_x_request_schema!("2.0.1", "NotifyEvent"),
  v2_x_request_schema!("2.0.1", "NotifyMonitoringReport"),
  v2_x_request_schema!("2.0.1", "NotifyReport"),
  v2_x_request_schema!("2.0.1", "PublishFirmware"),
  v2_x_request_schema!("2.0.1", "PublishFirmwareStatusNotification"),
  v2_x_request_schema!("2.0.1", "ReportChargingProfiles"),
  v2_x_request_schema!("2.0.1", "RequestStartTransaction"),
  v2_x_request_schema!("2.0.1", "RequestStopTransaction"),
  v2_x_request_schema!("2.0.1", "ReservationStatusUpdate"),
  v2_x_request_schema!("2.0.1", "ReserveNow"),
  v2_x_request_schema!("2.0.1", "Reset"),
  v2_x_request_schema!("2.0.1", "SecurityEventNotification"),
  v2_x_request_schema!("2.0.1", "SendLocalList"),
  v2_x_request_schema!("2.0.1", "SetChargingProfile"),
  v2_x_request_schema!("2.0.1", "SetDisplayMessage"),
  v2_x_request_schema!("2.0.1", "SetMonitoringBase"),
  v2_x_request_schema!("2.0.1", "SetMonitoringLevel"),
  v2_x_request_schema!("2.0.1", "SetNetworkProfile"),
  v2_x_request_schema!("2.0.1", "SetVariableMonitoring"),
  v2_x_request_schema!("2.0.1", "SetVariables"),
  v2_x_request_schema!("2.0.1", "SignCertificate"),
  v2_x_request_schema!("2.0.1", "StatusNotification"),
  v2_x_request_schema!("2.0.1", "TransactionEvent"),
  v2_x_request_schema!("2.0.1", "TriggerMessage"),
  v2_x_request_schema!("2.0.1", "UnlockConnector"),
  v2_x_request_schema!("2.0.1", "UnpublishFirmware"),
  v2_x_request_schema!("2.0.1", "UpdateFirmware"),
];

const V2_0_1_RESPONSE_SCHEMAS: &[EmbeddedSchema] = &[
  v2_x_response_schema!("2.0.1", "Authorize"),
  v2_x_response_schema!("2.0.1", "BootNotification"),
  v2_x_response_schema!("2.0.1", "CancelReservation"),
  v2_x_response_schema!("2.0.1", "CertificateSigned"),
  v2_x_response_schema!("2.0.1", "ChangeAvailability"),
  v2_x_response_schema!("2.0.1", "ClearCache"),
  v2_x_response_schema!("2.0.1", "ClearChargingProfile"),
  v2_x_response_schema!("2.0.1", "ClearDisplayMessage"),
  v2_x_response_schema!("2.0.1", "ClearVariableMonitoring"),
  v2_x_response_schema!("2.0.1", "ClearedChargingLimit"),
  v2_x_response_schema!("2.0.1", "CostUpdated"),
  v2_x_response_schema!("2.0.1", "CustomerInformation"),
  v2_x_response_schema!("2.0.1", "DataTransfer"),
  v2_x_response_schema!("2.0.1", "DeleteCertificate"),
  v2_x_response_schema!("2.0.1", "FirmwareStatusNotification"),
  v2_x_response_schema!("2.0.1", "Get15118EVCertificate"),
  v2_x_response_schema!("2.0.1", "GetBaseReport"),
  v2_x_response_schema!("2.0.1", "GetCertificateStatus"),
  v2_x_response_schema!("2.0.1", "GetChargingProfiles"),
  v2_x_response_schema!("2.0.1", "GetCompositeSchedule"),
  v2_x_response_schema!("2.0.1", "GetDisplayMessages"),
  v2_x_response_schema!("2.0.1", "GetInstalledCertificateIds"),
  v2_x_response_schema!("2.0.1", "GetLocalListVersion"),
  v2_x_response_schema!("2.0.1", "GetLog"),
  v2_x_response_schema!("2.0.1", "GetMonitoringReport"),
  v2_x_response_schema!("2.0.1", "GetReport"),
  v2_x_response_schema!("2.0.1", "GetTransactionStatus"),
  v2_x_response_schema!("2.0.1", "GetVariables"),
  v2_x_response_schema!("2.0.1", "Heartbeat"),
  v2_x_response_schema!("2.0.1", "InstallCertificate"),
  v2_x_response_schema!("2.0.1", "LogStatusNotification"),
  v2_x_response_schema!("2.0.1", "MeterValues"),
  v2_x_response_schema!("2.0.1", "NotifyChargingLimit"),
  v2_x_response_schema!("2.0.1", "NotifyCustomerInformation"),
  v2_x_response_schema!("2.0.1", "NotifyDisplayMessages"),
  v2_x_response_schema!("2.0.1", "NotifyEVChargingNeeds"),
  v2_x_response_schema!("2.0.1", "NotifyEVChargingSchedule"),
  v2_x_response_schema!("2.0.1", "NotifyEvent"),
  v2_x_response_schema!("2.0.1", "NotifyMonitoringReport"),
  v2_x_response_schema!("2.0.1", "NotifyReport"),
  v2_x_response_schema!("2.0.1", "PublishFirmware"),
  v2_x_response_schema!("2.0.1", "PublishFirmwareStatusNotification"),
  v2_x_response_schema!("2.0.1", "ReportChargingProfiles"),
  v2_x_response_schema!("2.0.1", "RequestStartTransaction"),
  v2_x_response_schema!("2.0.1", "RequestStopTransaction"),
  v2_x_response_schema!("2.0.1", "ReservationStatusUpdate"),
  v2_x_response_schema!("2.0.1", "ReserveNow"),
  v2_x_response_schema!("2.0.1", "Reset"),
  v2_x_response_schema!("2.0.1", "SecurityEventNotification"),
  v2_x_response_schema!("2.0.1", "SendLocalList"),
  v2_x_response_schema!("2.0.1", "SetChargingProfile"),
  v2_x_response_schema!("2.0.1", "SetDisplayMessage"),
  v2_x_response_schema!("2.0.1", "SetMonitoringBase"),
  v2_x_response_schema!("2.0.1", "SetMonitoringLevel"),
  v2_x_response_schema!("2.0.1", "SetNetworkProfile"),
  v2_x_response_schema!("2.0.1", "SetVariableMonitoring"),
  v2_x_response_schema!("2.0.1", "SetVariables"),
  v2_x_response_schema!("2.0.1", "SignCertificate"),
  v2_x_response_schema!("2.0.1", "StatusNotification"),
  v2_x_response_schema!("2.0.1", "TransactionEvent"),
  v2_x_response_schema!("2.0.1", "TriggerMessage"),
  v2_x_response_schema!("2.0.1", "UnlockConnector"),
  v2_x_response_schema!("2.0.1", "UnpublishFirmware"),
  v2_x_response_schema!("2.0.1", "UpdateFirmware"),
];

const V2_1_REQUEST_SCHEMAS: &[EmbeddedSchema] = &[
  v2_x_request_schema!("2.1", "AFRRSignal"),
  v2_x_request_schema!("2.1", "AdjustPeriodicEventStream"),
  v2_x_request_schema!("2.1", "Authorize"),
  v2_x_request_schema!("2.1", "BatterySwap"),
  v2_x_request_schema!("2.1", "BootNotification"),
  v2_x_request_schema!("2.1", "CancelReservation"),
  v2_x_request_schema!("2.1", "CertificateSigned"),
  v2_x_request_schema!("2.1", "ChangeAvailability"),
  v2_x_request_schema!("2.1", "ChangeTransactionTariff"),
  v2_x_request_schema!("2.1", "ClearCache"),
  v2_x_request_schema!("2.1", "ClearChargingProfile"),
  v2_x_request_schema!("2.1", "ClearDERControl"),
  v2_x_request_schema!("2.1", "ClearDisplayMessage"),
  v2_x_request_schema!("2.1", "ClearTariffs"),
  v2_x_request_schema!("2.1", "ClearVariableMonitoring"),
  v2_x_request_schema!("2.1", "ClearedChargingLimit"),
  v2_x_request_schema!("2.1", "ClosePeriodicEventStream"),
  v2_x_request_schema!("2.1", "CostUpdated"),
  v2_x_request_schema!("2.1", "CustomerInformation"),
  v2_x_request_schema!("2.1", "DataTransfer"),
  v2_x_request_schema!("2.1", "DeleteCertificate"),
  v2_x_request_schema!("2.1", "FirmwareStatusNotification"),
  v2_x_request_schema!("2.1", "Get15118EVCertificate"),
  v2_x_request_schema!("2.1", "GetBaseReport"),
  v2_x_request_schema!("2.1", "GetCertificateChainStatus"),
  v2_x_request_schema!("2.1", "GetCertificateStatus"),
  v2_x_request_schema!("2.1", "GetChargingProfiles"),
  v2_x_request_schema!("2.1", "GetCompositeSchedule"),
  v2_x_request_schema!("2.1", "GetDERControl"),
  v2_x_request_schema!("2.1", "GetDisplayMessages"),
  v2_x_request_schema!("2.1", "GetInstalledCertificateIds"),
  v2_x_request_schema!("2.1", "GetLocalListVersion"),
  v2_x_request_schema!("2.1", "GetLog"),
  v2_x_request_schema!("2.1", "GetMonitoringReport"),
  v2_x_request_schema!("2.1", "GetPeriodicEventStream"),
  v2_x_request_schema!("2.1", "GetReport"),
  v2_x_request_schema!("2.1", "GetTariffs"),
  v2_x_request_schema!("2.1", "GetTransactionStatus"),
  v2_x_request_schema!("2.1", "GetVariables"),
  v2_x_request_schema!("2.1", "Heartbeat"),
  v2_x_request_schema!("2.1", "InstallCertificate"),
  v2_x_request_schema!("2.1", "LogStatusNotification"),
  v2_x_request_schema!("2.1", "MeterValues"),
  v2_x_request_schema!("2.1", "NotifyAllowedEnergyTransfer"),
  v2_x_request_schema!("2.1", "NotifyChargingLimit"),
  v2_x_request_schema!("2.1", "NotifyCustomerInformation"),
  v2_x_request_schema!("2.1", "NotifyDERAlarm"),
  v2_x_request_schema!("2.1", "NotifyDERStartStop"),
  v2_x_request_schema!("2.1", "NotifyDisplayMessages"),
  v2_x_request_schema!("2.1", "NotifyEVChargingNeeds"),
  v2_x_request_schema!("2.1", "NotifyEVChargingSchedule"),
  v2_x_request_schema!("2.1", "NotifyEvent"),
  v2_x_request_schema!("2.1", "NotifyMonitoringReport"),
  v2_x_request_schema!(
    "2.1",
    "NotifyPeriodicEventStream",
    "NotifyPeriodicEventStream.json"
  ),
  v2_x_request_schema!("2.1", "NotifyPriorityCharging"),
  v2_x_request_schema!("2.1", "NotifyReport"),
  v2_x_request_schema!("2.1", "NotifySettlement"),
  v2_x_request_schema!("2.1", "NotifyWebPaymentStarted"),
  v2_x_request_schema!("2.1", "OpenPeriodicEventStream"),
  v2_x_request_schema!("2.1", "PublishFirmware"),
  v2_x_request_schema!("2.1", "PublishFirmwareStatusNotification"),
  v2_x_request_schema!("2.1", "PullDynamicScheduleUpdate"),
  v2_x_request_schema!("2.1", "ReportChargingProfiles"),
  v2_x_request_schema!("2.1", "ReportDERControl"),
  v2_x_request_schema!("2.1", "RequestBatterySwap"),
  v2_x_request_schema!("2.1", "RequestStartTransaction"),
  v2_x_request_schema!("2.1", "RequestStopTransaction"),
  v2_x_request_schema!("2.1", "ReservationStatusUpdate"),
  v2_x_request_schema!("2.1", "ReserveNow"),
  v2_x_request_schema!("2.1", "Reset"),
  v2_x_request_schema!("2.1", "SecurityEventNotification"),
  v2_x_request_schema!("2.1", "SendLocalList"),
  v2_x_request_schema!("2.1", "SetChargingProfile"),
  v2_x_request_schema!("2.1", "SetDERControl"),
  v2_x_request_schema!("2.1", "SetDefaultTariff"),
  v2_x_request_schema!("2.1", "SetDisplayMessage"),
  v2_x_request_schema!("2.1", "SetMonitoringBase"),
  v2_x_request_schema!("2.1", "SetMonitoringLevel"),
  v2_x_request_schema!("2.1", "SetNetworkProfile"),
  v2_x_request_schema!("2.1", "SetVariableMonitoring"),
  v2_x_request_schema!("2.1", "SetVariables"),
  v2_x_request_schema!("2.1", "SignCertificate"),
  v2_x_request_schema!("2.1", "StatusNotification"),
  v2_x_request_schema!("2.1", "TransactionEvent"),
  v2_x_request_schema!("2.1", "TriggerMessage"),
  v2_x_request_schema!("2.1", "UnlockConnector"),
  v2_x_request_schema!("2.1", "UnpublishFirmware"),
  v2_x_request_schema!("2.1", "UpdateDynamicSchedule"),
  v2_x_request_schema!("2.1", "UpdateFirmware"),
  v2_x_request_schema!("2.1", "UsePriorityCharging"),
  v2_x_request_schema!("2.1", "VatNumberValidation"),
];

const V2_1_RESPONSE_SCHEMAS: &[EmbeddedSchema] = &[
  v2_x_response_schema!("2.1", "AFRRSignal"),
  v2_x_response_schema!("2.1", "AdjustPeriodicEventStream"),
  v2_x_response_schema!("2.1", "Authorize"),
  v2_x_response_schema!("2.1", "BatterySwap"),
  v2_x_response_schema!("2.1", "BootNotification"),
  v2_x_response_schema!("2.1", "CancelReservation"),
  v2_x_response_schema!("2.1", "CertificateSigned"),
  v2_x_response_schema!("2.1", "ChangeAvailability"),
  v2_x_response_schema!("2.1", "ChangeTransactionTariff"),
  v2_x_response_schema!("2.1", "ClearCache"),
  v2_x_response_schema!("2.1", "ClearChargingProfile"),
  v2_x_response_schema!("2.1", "ClearDERControl"),
  v2_x_response_schema!("2.1", "ClearDisplayMessage"),
  v2_x_response_schema!("2.1", "ClearTariffs"),
  v2_x_response_schema!("2.1", "ClearVariableMonitoring"),
  v2_x_response_schema!("2.1", "ClearedChargingLimit"),
  v2_x_response_schema!("2.1", "ClosePeriodicEventStream"),
  v2_x_response_schema!("2.1", "CostUpdated"),
  v2_x_response_schema!("2.1", "CustomerInformation"),
  v2_x_response_schema!("2.1", "DataTransfer"),
  v2_x_response_schema!("2.1", "DeleteCertificate"),
  v2_x_response_schema!("2.1", "FirmwareStatusNotification"),
  v2_x_response_schema!("2.1", "Get15118EVCertificate"),
  v2_x_response_schema!("2.1", "GetBaseReport"),
  v2_x_response_schema!("2.1", "GetCertificateChainStatus"),
  v2_x_response_schema!("2.1", "GetCertificateStatus"),
  v2_x_response_schema!("2.1", "GetChargingProfiles"),
  v2_x_response_schema!("2.1", "GetCompositeSchedule"),
  v2_x_response_schema!("2.1", "GetDERControl"),
  v2_x_response_schema!("2.1", "GetDisplayMessages"),
  v2_x_response_schema!("2.1", "GetInstalledCertificateIds"),
  v2_x_response_schema!("2.1", "GetLocalListVersion"),
  v2_x_response_schema!("2.1", "GetLog"),
  v2_x_response_schema!("2.1", "GetMonitoringReport"),
  v2_x_response_schema!("2.1", "GetPeriodicEventStream"),
  v2_x_response_schema!("2.1", "GetReport"),
  v2_x_response_schema!("2.1", "GetTariffs"),
  v2_x_response_schema!("2.1", "GetTransactionStatus"),
  v2_x_response_schema!("2.1", "GetVariables"),
  v2_x_response_schema!("2.1", "Heartbeat"),
  v2_x_response_schema!("2.1", "InstallCertificate"),
  v2_x_response_schema!("2.1", "LogStatusNotification"),
  v2_x_response_schema!("2.1", "MeterValues"),
  v2_x_response_schema!("2.1", "NotifyAllowedEnergyTransfer"),
  v2_x_response_schema!("2.1", "NotifyChargingLimit"),
  v2_x_response_schema!("2.1", "NotifyCustomerInformation"),
  v2_x_response_schema!("2.1", "NotifyDERAlarm"),
  v2_x_response_schema!("2.1", "NotifyDERStartStop"),
  v2_x_response_schema!("2.1", "NotifyDisplayMessages"),
  v2_x_response_schema!("2.1", "NotifyEVChargingNeeds"),
  v2_x_response_schema!("2.1", "NotifyEVChargingSchedule"),
  v2_x_response_schema!("2.1", "NotifyEvent"),
  v2_x_response_schema!("2.1", "NotifyMonitoringReport"),
  v2_x_response_schema!("2.1", "NotifyPriorityCharging"),
  v2_x_response_schema!("2.1", "NotifyReport"),
  v2_x_response_schema!("2.1", "NotifySettlement"),
  v2_x_response_schema!("2.1", "NotifyWebPaymentStarted"),
  v2_x_response_schema!("2.1", "OpenPeriodicEventStream"),
  v2_x_response_schema!("2.1", "PublishFirmware"),
  v2_x_response_schema!("2.1", "PublishFirmwareStatusNotification"),
  v2_x_response_schema!("2.1", "PullDynamicScheduleUpdate"),
  v2_x_response_schema!("2.1", "ReportChargingProfiles"),
  v2_x_response_schema!("2.1", "ReportDERControl"),
  v2_x_response_schema!("2.1", "RequestBatterySwap"),
  v2_x_response_schema!("2.1", "RequestStartTransaction"),
  v2_x_response_schema!("2.1", "RequestStopTransaction"),
  v2_x_response_schema!("2.1", "ReservationStatusUpdate"),
  v2_x_response_schema!("2.1", "ReserveNow"),
  v2_x_response_schema!("2.1", "Reset"),
  v2_x_response_schema!("2.1", "SecurityEventNotification"),
  v2_x_response_schema!("2.1", "SendLocalList"),
  v2_x_response_schema!("2.1", "SetChargingProfile"),
  v2_x_response_schema!("2.1", "SetDERControl"),
  v2_x_response_schema!("2.1", "SetDefaultTariff"),
  v2_x_response_schema!("2.1", "SetDisplayMessage"),
  v2_x_response_schema!("2.1", "SetMonitoringBase"),
  v2_x_response_schema!("2.1", "SetMonitoringLevel"),
  v2_x_response_schema!("2.1", "SetNetworkProfile"),
  v2_x_response_schema!("2.1", "SetVariableMonitoring"),
  v2_x_response_schema!("2.1", "SetVariables"),
  v2_x_response_schema!("2.1", "SignCertificate"),
  v2_x_response_schema!("2.1", "StatusNotification"),
  v2_x_response_schema!("2.1", "TransactionEvent"),
  v2_x_response_schema!("2.1", "TriggerMessage"),
  v2_x_response_schema!("2.1", "UnlockConnector"),
  v2_x_response_schema!("2.1", "UnpublishFirmware"),
  v2_x_response_schema!("2.1", "UpdateDynamicSchedule"),
  v2_x_response_schema!("2.1", "UpdateFirmware"),
  v2_x_response_schema!("2.1", "UsePriorityCharging"),
  v2_x_response_schema!("2.1", "VatNumberValidation"),
];

#[cfg_attr(not(test), allow(dead_code))]
const ALL_SCHEMA_SETS: &[&[EmbeddedSchema]] = &[
  V1_6_REQUEST_SCHEMAS,
  V1_6_RESPONSE_SCHEMAS,
  V2_0_1_REQUEST_SCHEMAS,
  V2_0_1_RESPONSE_SCHEMAS,
  V2_1_REQUEST_SCHEMAS,
  V2_1_RESPONSE_SCHEMAS,
];

pub(crate) fn schemas(
  protocol: OcppVersion,
  schema_type: EmbeddedSchemaType,
) -> &'static [EmbeddedSchema] {
  match (protocol, schema_type) {
    (OcppVersion::V1_6, EmbeddedSchemaType::Request) => V1_6_REQUEST_SCHEMAS,
    (OcppVersion::V1_6, EmbeddedSchemaType::Response) => V1_6_RESPONSE_SCHEMAS,
    (OcppVersion::V2_0_1, EmbeddedSchemaType::Request) => {
      V2_0_1_REQUEST_SCHEMAS
    }
    (OcppVersion::V2_0_1, EmbeddedSchemaType::Response) => {
      V2_0_1_RESPONSE_SCHEMAS
    }
    (OcppVersion::V2_1, EmbeddedSchemaType::Request) => V2_1_REQUEST_SCHEMAS,
    (OcppVersion::V2_1, EmbeddedSchemaType::Response) => V2_1_RESPONSE_SCHEMAS,
  }
}

pub(crate) fn incoming_request_schemas(
  protocol: OcppVersion,
) -> &'static [EmbeddedSchema] {
  schemas(protocol, EmbeddedSchemaType::Request)
}

pub(crate) fn incoming_request_schema_text(
  protocol: OcppVersion,
  action: &str,
) -> Option<&'static str> {
  schema_text_for_action(incoming_request_schemas(protocol), action)
}

#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn schema_text(relative_path: &str) -> Option<&'static str> {
  ALL_SCHEMA_SETS.iter().find_map(|schemas| {
    schemas.iter().find_map(|schema| {
      (schema.relative_path == relative_path).then_some(schema.text)
    })
  })
}

fn schema_text_for_action(
  schemas: &[EmbeddedSchema],
  action: &str,
) -> Option<&'static str> {
  schemas
    .iter()
    .find_map(|schema| (schema.action == action).then_some(schema.text))
}

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

  #[test]
  fn embedded_schema_lookup_returns_known_actions() {
    let v1_6 = incoming_request_schema_text(OcppVersion::V1_6, "DataTransfer")
      .expect("v1.6 schema");
    assert!(v1_6.contains("\"vendorId\""));

    let v2_0_1 = incoming_request_schema_text(OcppVersion::V2_0_1, "Reset")
      .expect("v2.0.1 schema");
    assert!(v2_0_1.contains("\"type\""));

    let v2_1 = incoming_request_schema_text(
      OcppVersion::V2_1,
      "NotifyPeriodicEventStream",
    )
    .expect("v2.1 schema");
    assert!(v2_1.contains("\"basetime\""));

    let response = schema_text("schemas/2.0.1/GetVariablesResponse.json")
      .expect("embedded response schema");
    assert!(response.contains("\"getVariableResult\""));

    let unused_response = schema_text("schemas/2.1/AFRRSignalResponse.json")
      .expect("embedded unused response schema");
    assert!(unused_response.contains("\"$schema\""));

    assert!(
      incoming_request_schema_text(OcppVersion::V2_1, "TotallyUnknown")
        .is_none()
    );
  }

  #[test]
  fn embedded_schema_registry_covers_all_protocol_schema_sets() {
    assert_eq!(
      schemas(OcppVersion::V1_6, EmbeddedSchemaType::Request).len(),
      28
    );
    assert_eq!(
      schemas(OcppVersion::V1_6, EmbeddedSchemaType::Response).len(),
      28
    );
    assert_eq!(
      schemas(OcppVersion::V2_0_1, EmbeddedSchemaType::Request).len(),
      64
    );
    assert_eq!(
      schemas(OcppVersion::V2_0_1, EmbeddedSchemaType::Response).len(),
      64
    );
    assert_eq!(
      schemas(OcppVersion::V2_1, EmbeddedSchemaType::Request).len(),
      91
    );
    assert_eq!(
      schemas(OcppVersion::V2_1, EmbeddedSchemaType::Response).len(),
      90
    );
  }
}