mako_engine/erp.rs
1//! ERP integration traits and reference implementations.
2//!
3//! ## Role
4//!
5//! `mako-engine` is a protocol processor — it handles EDIFACT parsing, BDEW
6//! process rules, AS4 delivery, and regulatory deadlines. All contract data,
7//! billing logic, and master data live in the operator's ERP.
8//!
9//! This module defines the **stable integration contract** between `mako-engine`
10//! and external ERP or backend systems. The payload contract is **BO4E**, not
11//! raw EDIFACT. ERP adapters never see EDIFACT segment codes or format-version
12//! identifiers — those are absorbed inside `mako-engine`.
13//!
14//! ## Outbound: mako → ERP
15//!
16//! Implement [`ErpAdapter`] and register it at startup. Every domain event
17//! that requires ERP action is delivered as an [`ErpEvent`]. The production
18//! `WebhookErpAdapter` (in `makod`) serialises events as
19//! **[CloudEvents 1.0](https://cloudevents.io) structured-mode JSON** and POSTs
20//! them to the configured ERP endpoint.
21//!
22//! ```text
23//! POST <erp_webhook_url>
24//! Content-Type: application/cloudevents+json
25//! X-Idempotency-Key: <event.idempotency_key>
26//! X-Mako-Signature: <hmac-sha256-hex> ← only when secret is configured
27//!
28//! {
29//! "specversion": "1.0",
30//! "id": "<idempotency_key>",
31//! "source": "urn:mako:tenant:<tenant_id>",
32//! "type": "de.mako.aperak.accepted",
33//! "time": "2026-10-01T10:15:00+02:00",
34//! "subject": "<process_id>",
35//! "dataschema": "https://.../Marktlokation.json",
36//! "datacontenttype": "application/json",
37//! "makoconvid": "<conversation_id>",
38//! "makocausationid": "<causation_id>",
39//! "makopid": 55001,
40//! "data": { "_typ": "MARKTLOKATION", ... }
41//! }
42//! ```
43//!
44//! See [`ErpEventType::cloud_event_type`] for the full type → CE type mapping.
45//! The BO4E payload is always in the `data` field; the `payload_schema` URL
46//! maps to the CloudEvents `dataschema` attribute.
47//!
48//! ## Inbound: ERP → mako (event-driven)
49//!
50//! For ERP systems with a message bus, implement [`ErpCommandSource`] to feed
51//! BO4E business objects into the engine without a synchronous REST round-trip.
52//!
53//! ```rust,ignore
54//! struct MyKafkaSource { consumer: KafkaConsumer }
55//!
56//! impl ErpCommandSource for MyKafkaSource {
57//! async fn next(&self) -> Result<Option<InboundErpCommand>, ErpAdapterError> {
58//! let msg = self.consumer.poll(Duration::from_millis(100)).await;
59//! Ok(msg.map(|m| InboundErpCommand {
60//! idempotency_key: m.offset().to_string(),
61//! tenant_id: TenantId::new(),
62//! payload_schema: "…/Marktlokation.json".into(),
63//! payload: serde_json::from_slice(m.payload()).unwrap(),
64//! }))
65//! }
66//!
67//! async fn ack(&self, id: &str) -> Result<(), ErpAdapterError> {
68//! self.consumer.commit_offset(id.parse().unwrap()).await
69//! .map_err(ErpAdapterError::transport)
70//! }
71//!
72//! async fn nack(&self, _id: &str, _reason: &str) -> Result<(), ErpAdapterError> {
73//! Ok(()) // Kafka auto-redelivers on next poll
74//! }
75//! }
76//! ```
77//!
78//! ## Reference implementations
79//!
80//! | Type | Feature | Use case |
81//! |------|---------|---------|
82//! | `NoopErpAdapter` | `testing` | Unit tests, CI |
83//! | [`LogErpAdapter`] | — | Structured log output; starting point for new integrations |
84//! | `NoopErpCommandSource` | `testing` | No-op inbound source for tests |
85//!
86//! For the production `WebhookErpAdapter` and `POST /api/v1/commands` endpoint,
87//! see `makod/src/erp_adapter.rs`.
88
89use std::sync::Arc;
90
91use serde::{Deserialize, Serialize};
92use time::OffsetDateTime;
93
94use crate::erc::ErcCode;
95use crate::ids::{ConversationId, EventId, ProcessId, TenantId};
96
97// ── ErpAdapterError ───────────────────────────────────────────────────────────
98
99/// Errors produced by [`ErpAdapter`] and [`ErpCommandSource`] implementations.
100#[derive(Debug, thiserror::Error)]
101pub enum ErpAdapterError {
102 /// The ERP response payload could not be deserialised or is semantically
103 /// invalid.
104 #[error("ERP payload error: {0}")]
105 Payload(String),
106
107 /// A transient transport error (network timeout, HTTP 5xx, broker
108 /// disconnect). The delivery worker will retry with exponential backoff.
109 #[error("ERP transport error: {0}")]
110 Transport(String),
111
112 /// A permanent, non-retryable error (e.g. invalid configuration,
113 /// authentication failure). The delivery worker will dead-letter the
114 /// message.
115 #[error("ERP permanent error: {0}")]
116 Permanent(String),
117}
118
119impl ErpAdapterError {
120 /// Construct a [`Payload`](ErpAdapterError::Payload) variant.
121 pub fn payload(e: impl std::fmt::Display) -> Self {
122 Self::Payload(e.to_string())
123 }
124
125 /// Construct a [`Transport`](ErpAdapterError::Transport) variant.
126 pub fn transport(e: impl std::fmt::Display) -> Self {
127 Self::Transport(e.to_string())
128 }
129
130 /// Construct a [`Permanent`](ErpAdapterError::Permanent) variant.
131 pub fn permanent(e: impl std::fmt::Display) -> Self {
132 Self::Permanent(e.to_string())
133 }
134
135 /// Returns `true` for transient errors that warrant a retry.
136 #[must_use]
137 pub fn is_retryable(&self) -> bool {
138 matches!(self, Self::Transport(_))
139 }
140}
141
142// ── ErpEventType ─────────────────────────────────────────────────────────────
143
144/// Semantic classification of an outbound ERP process event.
145///
146/// The ERP uses this to decide which action to take — update an order status,
147/// trigger a billing run, open a complaint ticket, etc.
148#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
149#[serde(rename_all = "snake_case")]
150pub enum ErpEventType {
151 /// A new MaKo process was spawned (e.g. inbound UTILMD received).
152 ProcessInitiated,
153 /// The counterparty sent an APERAK accepting our UTILMD.
154 AperakAccepted,
155 /// The counterparty sent an APERAK rejecting our UTILMD.
156 ///
157 /// `erc_code` is `Some` when the APERAK carried a structured ERC segment
158 /// (BDEW APERAK AHB 1.0 §2.2). It is `None` for legacy outbox messages
159 /// that predate the typed ERC code field.
160 AperakRejected {
161 /// Structured BDEW ERC error code from the APERAK ERC segment.
162 ///
163 /// Use [`crate::erc::recommended_action`] to derive the
164 /// recommended automated ERP response.
165 #[serde(skip_serializing_if = "Option::is_none")]
166 erc_code: Option<ErcCode>,
167 },
168 /// No APERAK received within the regulatory SLA window (deadline expired).
169 AperakTimeout,
170 /// A CONTRL syntax acknowledgement was received.
171 ContrlReceived,
172 /// The process reached its terminal success state
173 /// (e.g. Lieferbeginn/Lieferende confirmed).
174 ProcessCompleted,
175 /// A MaLo identification request was successfully resolved: the MaLo was
176 /// found and the positive callback was delivered to the requesting LF.
177 ///
178 /// The `payload` field of the associated [`ErpEvent`] carries a BO4E
179 /// `Marktlokation` JSON object with the resolved MaLo data.
180 MaloIdentified,
181 /// The process failed permanently (regulatory timeout, data error, …).
182 ProcessFailed {
183 /// Human-readable failure description.
184 reason: Box<str>,
185 },
186 /// A WiM Steuerungsauftrag (PID 55168) dispatch was positively confirmed by
187 /// the MSB (`EndantwortPositiv`). Triggers downstream VPP settlement billing
188 /// in `billingd` via `POST /api/v1/webhooks/vpp-dispatch`.
189 ///
190 /// Only emitted for `Konfiguration` (load-reduction) commands — not for
191 /// `InitialZustand` (reset) commands, which restore normal operation.
192 ///
193 /// The CE `data` payload carries:
194 /// `tx_id`, `location_id`, `location_type`, `execution_time_from`,
195 /// `execution_time_until`, `max_power_kw`, `command_type`, `sender_mp_id`,
196 /// `produkt_code`.
197 VppDispatchConfirmed,
198}
199
200impl ErpEventType {
201 /// Short label for structured logging and metrics.
202 #[must_use]
203 pub fn label(&self) -> &'static str {
204 match self {
205 Self::ProcessInitiated => "process_initiated",
206 Self::AperakAccepted => "aperak_accepted",
207 Self::AperakRejected { .. } => "aperak_rejected",
208 Self::AperakTimeout => "aperak_timeout",
209 Self::ContrlReceived => "contrl_received",
210 Self::ProcessCompleted => "process_completed",
211 Self::MaloIdentified => "malo_identified",
212 Self::ProcessFailed { .. } => "process_failed",
213 Self::VppDispatchConfirmed => "vpp_dispatch_confirmed",
214 }
215 }
216
217 /// CloudEvents 1.0 `type` attribute for this event.
218 ///
219 /// Follows the reverse-DNS prefix convention (`de.mako.<domain>.<action>`).
220 /// Used by the `WebhookErpAdapter` to populate the `type` field of the
221 /// CloudEvents envelope.
222 #[must_use]
223 pub fn cloud_event_type(&self) -> &'static str {
224 match self {
225 Self::ProcessInitiated => "de.mako.process.initiated",
226 Self::AperakAccepted => "de.mako.aperak.accepted",
227 Self::AperakRejected { .. } => "de.mako.aperak.rejected",
228 Self::AperakTimeout => "de.mako.aperak.timeout",
229 Self::ContrlReceived => "de.mako.contrl.received",
230 Self::ProcessCompleted => "de.mako.process.completed",
231 Self::MaloIdentified => "de.mako.malo.identified",
232 Self::ProcessFailed { .. } => "de.mako.process.failed",
233 Self::VppDispatchConfirmed => "de.vpp.dispatch.confirmed",
234 }
235 }
236}
237
238// ── ErpEvent ──────────────────────────────────────────────────────────────────
239
240/// A structured process event delivered from `mako-engine` to the ERP.
241///
242/// The payload is always a **BO4E-typed JSON object** — the ERP adapter never
243/// receives raw EDIFACT bytes or EDIFACT format-version identifiers.
244///
245/// On the wire (via `WebhookErpAdapter`) this struct is serialised as a
246/// **[CloudEvents 1.0](https://cloudevents.io) structured-mode JSON** envelope
247/// with `Content-Type: application/cloudevents+json`. The BO4E payload lives
248/// in the CloudEvents `data` field; `payload_schema` maps to `dataschema`;
249/// `event_type` maps to the `type` attribute via [`ErpEventType::cloud_event_type`].
250///
251/// ## Idempotency
252///
253/// `idempotency_key` maps to the CloudEvents `id` attribute and is also sent
254/// as `X-Idempotency-Key` for ERP middleware that keys on headers. The ERP
255/// **must** persist this key and return `HTTP 200 OK` for duplicate deliveries.
256#[derive(Debug, Clone, Serialize, Deserialize)]
257pub struct ErpEvent {
258 /// Stable dedup key — store in the ERP to reject duplicate deliveries.
259 ///
260 /// Derived from the outbox `message_id`; stable across retries.
261 pub idempotency_key: String,
262
263 /// Semantic classification of this event.
264 pub event_type: ErpEventType,
265
266 /// The mako process that generated this event.
267 pub process_id: ProcessId,
268
269 /// Tenant (operator GLN) that owns this process.
270 pub tenant_id: TenantId,
271
272 /// BDEW business conversation identifier.
273 pub conversation_id: ConversationId,
274
275 /// The mako domain event that directly caused this ERP notification.
276 pub causation_id: EventId,
277
278 /// Prüfidentifikator of the process.
279 pub pid: u32,
280
281 /// BO4E JSON Schema URL that validates [`payload`](ErpEvent::payload).
282 ///
283 /// Examples:
284 /// - `"https://raw.githubusercontent.com/BO4E/BO4E-Schemas/v202607.0.0/src/bo4e_schemas/bo/Marktlokation.json"`
285 /// - `"https://raw.githubusercontent.com/BO4E/BO4E-Schemas/v202607.0.0/src/bo4e_schemas/bo/Messlokation.json"`
286 ///
287 /// `None` for events where no primary BO4E object is applicable
288 /// (e.g. `ContrlReceived`).
289 #[serde(skip_serializing_if = "Option::is_none")]
290 pub payload_schema: Option<String>,
291
292 /// BO4E-typed payload.
293 ///
294 /// Deserialise using the ERP's own BO4E library. Raw EDIFACT structures
295 /// are never exposed here. `null` when no payload is applicable.
296 pub payload: serde_json::Value,
297
298 /// Wall-clock time when the domain event was persisted.
299 pub occurred_at: OffsetDateTime,
300
301 /// Workflow family name that produced this event (e.g. `"gpke-sperrung"`).
302 ///
303 /// Carried through from `OutboxMessage::workflow_name`. Emitted as the
304 /// `makoworkflow` CloudEvents extension attribute by `WebhookErpAdapter`.
305 /// `marktd` maps this to `marktrole` for role-scoped ERP subscriber fan-out.
306 ///
307 /// Empty string for events produced by legacy outbox messages that
308 /// predate this field.
309 pub workflow_name: Box<str>,
310}
311
312// ── ErpAdapter trait ──────────────────────────────────────────────────────────
313
314/// Outbound notification sink — `mako-engine` calls this when a process event
315/// should be reported to the ERP.
316///
317/// The payload is always a BO4E-typed JSON object; the adapter never receives
318/// raw EDIFACT bytes or format-version identifiers.
319///
320/// ## Contract
321///
322/// - Must be **idempotent** on `event.idempotency_key`. Called twice with the
323/// same key must succeed without double-posting.
324/// - Return [`ErpAdapterError::Transport`] for transient failures — the caller
325/// will retry with exponential backoff.
326/// - Return [`ErpAdapterError::Permanent`] for non-retryable failures — the
327/// caller will dead-letter the event.
328#[allow(async_fn_in_trait)]
329pub trait ErpAdapter: Send + Sync + 'static {
330 /// Deliver `event` to the ERP.
331 async fn notify(&self, event: ErpEvent) -> Result<(), ErpAdapterError>;
332}
333
334/// Blanket `Arc` implementation so `ErpAdapter` can be shared across tasks.
335impl<T: ErpAdapter> ErpAdapter for Arc<T> {
336 async fn notify(&self, event: ErpEvent) -> Result<(), ErpAdapterError> {
337 (**self).notify(event).await
338 }
339}
340
341// ── InboundErpCommand ─────────────────────────────────────────────────────────
342
343/// A BO4E business object received from the ERP, intended to trigger a mako
344/// process.
345///
346/// `mako-engine` maps the BO4E payload to an internal `Command` via the
347/// domain crate's command mapper.
348#[derive(Debug, Clone, Serialize, Deserialize)]
349pub struct InboundErpCommand {
350 /// Stable dedup key — forwarded to [`InboxStore::accept`].
351 ///
352 /// The ERP must supply a stable, unique identifier per command so that
353 /// retransmissions do not double-execute the workflow.
354 ///
355 /// [`InboxStore::accept`]: crate::inbox::InboxStore::accept
356 pub idempotency_key: String,
357
358 /// Tenant (operator GLN) that owns the target process.
359 pub tenant_id: TenantId,
360
361 /// BO4E JSON Schema URL — identifies the object type without inspecting
362 /// `payload`.
363 ///
364 /// Example:
365 /// `"https://raw.githubusercontent.com/BO4E/BO4E-Schemas/v202607.0.0/src/bo4e_schemas/bo/Vertrag.json"`
366 pub payload_schema: String,
367
368 /// BO4E-typed JSON payload. `mako-engine` maps this to an internal
369 /// `Command` via the registered domain command mapper.
370 pub payload: serde_json::Value,
371}
372
373// ── ErpCommandSource trait ────────────────────────────────────────────────────
374
375/// Inbound command source — `mako-engine` polls this for new BO4E objects
376/// from the ERP.
377///
378/// Implement this for broker-based inbound flows (Kafka consumer, SFTP poll,
379/// database change feed, …) to make the entire integration fully event-driven
380/// — no synchronous REST round-trip required.
381///
382/// ## Contract
383///
384/// - [`next`](ErpCommandSource::next) must be **non-blocking** when idle —
385/// return `Ok(None)` immediately when no command is available.
386/// - [`ack`](ErpCommandSource::ack) must suppress re-delivery of `id` after
387/// a successful ack (idempotent).
388/// - [`nack`](ErpCommandSource::nack) should allow re-delivery of `id` after
389/// an appropriate backoff.
390#[allow(async_fn_in_trait)]
391pub trait ErpCommandSource: Send + Sync + 'static {
392 /// Return the next pending BO4E command, or `None` when the source is idle.
393 async fn next(&self) -> Result<Option<InboundErpCommand>, ErpAdapterError>;
394
395 /// Acknowledge successful processing of `id`.
396 ///
397 /// After a successful ack the source must not re-deliver `id`.
398 async fn ack(&self, id: &str) -> Result<(), ErpAdapterError>;
399
400 /// Negative-acknowledge — allow re-delivery of `id` after backoff.
401 async fn nack(&self, id: &str, reason: &str) -> Result<(), ErpAdapterError>;
402}
403
404/// Blanket `Arc` implementation so `ErpCommandSource` can be shared across tasks.
405impl<S: ErpCommandSource> ErpCommandSource for Arc<S> {
406 async fn next(&self) -> Result<Option<InboundErpCommand>, ErpAdapterError> {
407 (**self).next().await
408 }
409 async fn ack(&self, id: &str) -> Result<(), ErpAdapterError> {
410 (**self).ack(id).await
411 }
412 async fn nack(&self, id: &str, reason: &str) -> Result<(), ErpAdapterError> {
413 (**self).nack(id, reason).await
414 }
415}
416
417// ── NoopErpAdapter ────────────────────────────────────────────────────────────
418
419/// An [`ErpAdapter`] that succeeds immediately without notifying anything.
420///
421/// Use in unit tests and CI where no real ERP endpoint is available.
422#[cfg(feature = "testing")]
423#[derive(Debug, Clone, Default)]
424pub struct NoopErpAdapter;
425
426#[cfg(feature = "testing")]
427impl ErpAdapter for NoopErpAdapter {
428 async fn notify(&self, _event: ErpEvent) -> Result<(), ErpAdapterError> {
429 Ok(())
430 }
431}
432
433// ── LogErpAdapter ─────────────────────────────────────────────────────────────
434
435/// An [`ErpAdapter`] that logs every event at `info` level without delivering
436/// it.
437///
438/// Useful as a development starting point — replace it with your concrete ERP
439/// adapter in production.
440#[derive(Debug, Clone, Default)]
441pub struct LogErpAdapter;
442
443impl ErpAdapter for LogErpAdapter {
444 async fn notify(&self, event: ErpEvent) -> Result<(), ErpAdapterError> {
445 tracing::info!(
446 idempotency_key = %event.idempotency_key,
447 event_type = event.event_type.label(),
448 process_id = %event.process_id,
449 tenant_id = %event.tenant_id,
450 pid = event.pid,
451 "ErpAdapter: event logged (no delivery configured)",
452 );
453 Ok(())
454 }
455}
456
457// ── NoopErpCommandSource ──────────────────────────────────────────────────────
458
459/// An [`ErpCommandSource`] that is always idle (returns `Ok(None)`).
460///
461/// Use in tests where no inbound ERP command flow is needed.
462#[cfg(feature = "testing")]
463#[derive(Debug, Clone, Default)]
464pub struct NoopErpCommandSource;
465
466#[cfg(feature = "testing")]
467impl ErpCommandSource for NoopErpCommandSource {
468 async fn next(&self) -> Result<Option<InboundErpCommand>, ErpAdapterError> {
469 Ok(None)
470 }
471 async fn ack(&self, _id: &str) -> Result<(), ErpAdapterError> {
472 Ok(())
473 }
474 async fn nack(&self, _id: &str, _reason: &str) -> Result<(), ErpAdapterError> {
475 Ok(())
476 }
477}
478
479// ── ErpAdapterTestHarness ─────────────────────────────────────────────────────
480
481/// A recording [`ErpAdapter`] for use in tests.
482///
483/// Records every [`ErpEvent`] delivered via [`notify`](ErpAdapter::notify) so
484/// tests can assert on event types, ordering, and BO4E payload shapes.
485///
486/// ```rust,ignore
487/// let harness = ErpAdapterTestHarness::new();
488/// my_workflow.run_with_adapter(harness.adapter()).await?;
489///
490/// let events = harness.events();
491/// assert_eq!(events[0].event_type, ErpEventType::ProcessInitiated);
492/// assert_eq!(events[1].event_type, ErpEventType::AperakAccepted);
493/// ```
494#[cfg(feature = "testing")]
495#[derive(Debug, Clone, Default)]
496pub struct ErpAdapterTestHarness {
497 events: Arc<tokio::sync::Mutex<Vec<ErpEvent>>>,
498}
499
500#[cfg(feature = "testing")]
501impl ErpAdapterTestHarness {
502 /// Create a new empty harness.
503 #[must_use]
504 pub fn new() -> Self {
505 Self::default()
506 }
507
508 /// Return a snapshot of all recorded events in delivery order.
509 pub async fn events(&self) -> Vec<ErpEvent> {
510 self.events.lock().await.clone()
511 }
512
513 /// Drain all recorded events, resetting the harness.
514 pub async fn drain(&self) -> Vec<ErpEvent> {
515 std::mem::take(&mut *self.events.lock().await)
516 }
517}
518
519#[cfg(feature = "testing")]
520impl ErpAdapter for ErpAdapterTestHarness {
521 async fn notify(&self, event: ErpEvent) -> Result<(), ErpAdapterError> {
522 self.events.lock().await.push(event);
523 Ok(())
524 }
525}
526
527// ── ErpCommandSourceTestHarness ───────────────────────────────────────────────
528
529/// A controllable [`ErpCommandSource`] for use in tests.
530///
531/// Inject canned [`InboundErpCommand`] payloads and verify that the engine
532/// processes them correctly.
533///
534/// ```text
535/// let source = ErpCommandSourceTestHarness::new();
536/// source.inject(InboundErpCommand {
537/// idempotency_key: "order-42".into(),
538/// tenant_id: TenantId::new(),
539/// payload_schema: ".../Vertrag.json".into(),
540/// payload: serde_json::json!({ "_typ": "VERTRAG", ... }),
541/// }).await;
542///
543/// // The engine picks up the command on the next poll.
544/// ```
545#[cfg(feature = "testing")]
546#[derive(Debug, Clone, Default)]
547pub struct ErpCommandSourceTestHarness {
548 queue: Arc<tokio::sync::Mutex<std::collections::VecDeque<InboundErpCommand>>>,
549 acked: Arc<tokio::sync::Mutex<Vec<String>>>,
550 nacked: Arc<tokio::sync::Mutex<Vec<(String, String)>>>,
551}
552
553#[cfg(feature = "testing")]
554impl ErpCommandSourceTestHarness {
555 /// Create a new empty harness.
556 #[must_use]
557 pub fn new() -> Self {
558 Self::default()
559 }
560
561 /// Enqueue a command to be returned by the next [`next`](ErpCommandSource::next) call.
562 pub async fn inject(&self, cmd: InboundErpCommand) {
563 self.queue.lock().await.push_back(cmd);
564 }
565
566 /// Return all acked command IDs.
567 pub async fn acked(&self) -> Vec<String> {
568 self.acked.lock().await.clone()
569 }
570
571 /// Return all nacked `(id, reason)` pairs.
572 pub async fn nacked(&self) -> Vec<(String, String)> {
573 self.nacked.lock().await.clone()
574 }
575}
576
577#[cfg(feature = "testing")]
578impl ErpCommandSource for ErpCommandSourceTestHarness {
579 async fn next(&self) -> Result<Option<InboundErpCommand>, ErpAdapterError> {
580 Ok(self.queue.lock().await.pop_front())
581 }
582
583 async fn ack(&self, id: &str) -> Result<(), ErpAdapterError> {
584 self.acked.lock().await.push(id.to_owned());
585 Ok(())
586 }
587
588 async fn nack(&self, id: &str, reason: &str) -> Result<(), ErpAdapterError> {
589 self.nacked
590 .lock()
591 .await
592 .push((id.to_owned(), reason.to_owned()));
593 Ok(())
594 }
595}
596
597// ── BO4E schema URL constants ─────────────────────────────────────────────────
598
599/// BO4E schema URL base for v202607.0.0.
600///
601/// Use `bo4e_schema_url!(Marktlokation)` to construct typed schema URLs at
602/// compile time.
603pub const BO4E_V202607_BASE: &str =
604 "https://raw.githubusercontent.com/BO4E/BO4E-Schemas/v202607.0.0/src/bo4e_schemas";
605
606/// Construct a BO4E v202607.0.0 JSON Schema URL for a Business Object.
607///
608/// ```rust
609/// use mako_engine::bo4e_schema_url;
610/// assert!(bo4e_schema_url!("bo", "Marktlokation").contains("Marktlokation"));
611/// ```
612#[macro_export]
613macro_rules! bo4e_schema_url {
614 ($category:literal, $name:literal) => {
615 concat!(
616 "https://raw.githubusercontent.com/BO4E/BO4E-Schemas/v202607.0.0/src/bo4e_schemas/",
617 $category,
618 "/",
619 $name,
620 ".json",
621 )
622 };
623}
624
625/// BO4E JSON Schema URL for `Marktlokation`.
626pub const BO4E_SCHEMA_MARKTLOKATION: &str = bo4e_schema_url!("bo", "Marktlokation");
627
628/// BO4E JSON Schema URL for `Messlokation`.
629pub const BO4E_SCHEMA_MESSLOKATION: &str = bo4e_schema_url!("bo", "Messlokation");
630
631/// BO4E JSON Schema URL for `Vertrag`.
632pub const BO4E_SCHEMA_VERTRAG: &str = bo4e_schema_url!("bo", "Vertrag");
633
634/// BO4E JSON Schema URL for `Energiemenge`.
635pub const BO4E_SCHEMA_ENERGIEMENGE: &str = bo4e_schema_url!("bo", "Energiemenge");
636
637/// BO4E JSON Schema URL for `Rechnung`.
638pub const BO4E_SCHEMA_RECHNUNG: &str = bo4e_schema_url!("bo", "Rechnung");
639
640/// BO4E JSON Schema URL for `Zaehler`.
641pub const BO4E_SCHEMA_ZAEHLER: &str = bo4e_schema_url!("bo", "Zaehler");
642
643/// BO4E JSON Schema URL for `Geschaeftspartner`.
644pub const BO4E_SCHEMA_GESCHAEFTSPARTNER: &str = bo4e_schema_url!("bo", "Geschaeftspartner");