Skip to main content

redispatch_xml/documents/
status_request.rs

1//! `StatusRequest_MarketDocument` — TSO/DSO request for the current status of a Redispatch resource.
2use serde::{Deserialize, Serialize};
3
4use crate::documents::kaskade::ParticipantMrid;
5use crate::types::{Mrid, SimpleContent, UtcDateTime};
6
7// ── Namespace ─────────────────────────────────────────────────────────────────
8
9/// Expected XML namespace for `StatusRequest_MarketDocument`.
10pub const NAMESPACE: &str = "urn:iec62325.351:tc57wg16:451-5:statusrequestdocument:4:1";
11
12// ── Enumerations ──────────────────────────────────────────────────────────────
13
14/// Document type for `StatusRequest_MarketDocument`.
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
16pub enum StatusRequestDocType {
17    /// Status request.
18    #[serde(rename = "A60")]
19    StatusRequest,
20    /// Catalogue request.
21    #[serde(rename = "Z15")]
22    CatalogueRequest,
23}
24
25/// Sender role for `StatusRequest_MarketDocument`.
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
27pub enum StatusRequestSenderRole {
28    /// Grid operator.
29    #[serde(rename = "A18")]
30    GridOperator,
31    /// Data provider.
32    #[serde(rename = "A39")]
33    DataProvider,
34}
35
36/// Receiver role for `StatusRequest_MarketDocument`.
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
38pub enum StatusRequestReceiverRole {
39    /// Grid operator.
40    #[serde(rename = "A18")]
41    GridOperator,
42    /// Resource provider.
43    #[serde(rename = "A27")]
44    ResourceProvider,
45    /// Other / central.
46    #[serde(rename = "Z01")]
47    Other,
48}
49
50/// Market participant status used in `MktActivityRecord`.
51#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
52pub enum ParticipantStatus {
53    /// Deactivated.
54    #[serde(rename = "A03")]
55    Deactivated,
56    /// Reactivated.
57    #[serde(rename = "A04")]
58    Reactivated,
59    /// Withdrawn.
60    #[serde(rename = "A13")]
61    Withdrawn,
62}
63
64// ── Sender / receiver ────────────────────────────────────────────────────────
65//
66// Flat, dotted elements on the wire — `<sender_MarketParticipant.mRID>` and
67// `<sender_MarketParticipant.marketRole.type>` — not a nested
68// `<sender_MarketParticipant>` container. That is the ENTSO-E CIM convention
69// the BDEW XSD follows, and the difference is not cosmetic: a nested document
70// fails XSD validation at the counterparty, and an inbound flat one loses the
71// sender entirely, because `serde` skips elements the model does not declare.
72
73// ── AttributeInstanceComponent ────────────────────────────────────────────────
74
75/// A generic key–value attribute (used for query parameters in status requests).
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
77pub struct AttributeInstanceComponent {
78    /// Attribute name.
79    #[serde(rename = "attribute")]
80    pub attribute: String,
81    /// Attribute value.
82    #[serde(
83        rename = "attributeValue",
84        default,
85        skip_serializing_if = "Option::is_none"
86    )]
87    pub attribute_value: Option<String>,
88}
89
90// ── MktActivityRecord ─────────────────────────────────────────────────────────
91
92/// Participant status record in a `StatusRequest_MarketDocument`.
93#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
94pub struct MktActivityRecord {
95    /// Market participant identifier (max 16 chars).
96    #[serde(rename = "MarketParticipant.mRID")]
97    pub market_participant_m_rid: SimpleContent<String>,
98    /// Participant status: deactivated, reactivated, or withdrawn.
99    pub status: ParticipantStatus,
100}
101
102// ── StatusRequest_MarketDocument ──────────────────────────────────────────────
103
104/// `StatusRequest_MarketDocument` — status request from a grid operator for
105/// resource provider participation data.
106///
107/// XSD version: 1.1 (2025-04-01)  
108/// Namespace: `urn:iec62325.351:tc57wg16:451-5:statusrequestdocument:4:1`
109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
110#[serde(rename = "StatusRequest_MarketDocument")]
111pub struct StatusRequestMarketDocument {
112    /// Unique message identifier (max 35 chars).
113    #[serde(rename = "mRID")]
114    pub m_rid: Mrid,
115    /// Document type.
116    #[serde(rename = "type")]
117    pub doc_type: StatusRequestDocType,
118    /// Sender market participant identifier.
119    #[serde(rename = "sender_MarketParticipant.mRID")]
120    pub sender_m_rid: ParticipantMrid,
121    /// Sender market role.
122    #[serde(rename = "sender_MarketParticipant.marketRole.type")]
123    pub sender_market_role: StatusRequestSenderRole,
124    /// Receiver market participant identifier.
125    #[serde(rename = "receiver_MarketParticipant.mRID")]
126    pub receiver_m_rid: ParticipantMrid,
127    /// Receiver market role.
128    #[serde(rename = "receiver_MarketParticipant.marketRole.type")]
129    pub receiver_market_role: StatusRequestReceiverRole,
130    /// Document creation timestamp (UTC, second precision).
131    #[serde(rename = "createdDateTime")]
132    pub created_date_time: UtcDateTime,
133    /// Generic attribute–value components (query parameters).
134    #[serde(
135        rename = "AttributeInstanceComponent",
136        default,
137        skip_serializing_if = "Vec::is_empty"
138    )]
139    pub attributes: Vec<AttributeInstanceComponent>,
140    /// Participant status records.
141    #[serde(
142        rename = "MktActivityRecord",
143        default,
144        skip_serializing_if = "Vec::is_empty"
145    )]
146    pub mkt_activity_records: Vec<MktActivityRecord>,
147}