Skip to main content

redispatch_xml/documents/
kostenblatt.rs

1use serde::{Deserialize, Serialize};
2
3use crate::documents::activation::{ControlZoneRef, ResourceObjectRef};
4use crate::documents::planned_resource_schedule::Product;
5use crate::types::{
6    AttrV, AttrVWithScheme, Direction, DocumentId, DocumentVersion, MarketParticipantId,
7    MarketRoleType, Period, TimeInterval, UtcDateTime,
8};
9
10// ── DocumentType ──────────────────────────────────────────────────────────────
11
12/// `DocumentType` for `Kostenblatt` (always `Z05`).
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
14pub enum KostenblattDocType {
15    /// Cost sheet (Kostenblatt).
16    #[serde(rename = "Z05")]
17    Kostenblatt,
18}
19
20/// `ProcessType` for `Kostenblatt` (always `A14`).
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
22pub enum KostenblattProcessType {
23    /// Forecast (Planungsdaten).
24    #[serde(rename = "A14")]
25    Forecast,
26}
27
28/// `BusinessType` codes for `CostTimeSeries`.
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
30pub enum CostBusinessType {
31    /// Production — energy-dependent costs (Arbeitspreis).
32    #[serde(rename = "A01")]
33    ProductionEnergy,
34    /// Consumption — energy-dependent costs.
35    #[serde(rename = "A04")]
36    ConsumptionEnergy,
37    /// Startup costs (Anfahrkosten).
38    #[serde(rename = "Z01")]
39    StartupCosts,
40    /// Extra operating-hour costs (Betriebsstundenkosten).
41    #[serde(rename = "Z02")]
42    ExtraOperatingHourCosts,
43    /// Avoided network fees (vermiedene Netzentgelte).
44    #[serde(rename = "Z03")]
45    AvoidedNetworkFees,
46    /// Additional wRDV costs.
47    #[serde(rename = "Z06")]
48    AdditionalWrdvCosts,
49}
50
51// ── CostTimeSeries ────────────────────────────────────────────────────────────
52
53/// A single cost time series within a `Kostenblatt`.
54#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
55pub struct CostTimeSeries {
56    /// Unique time-series identifier (max 35 chars).
57    #[serde(rename = "TimeSeriesIdentification")]
58    pub time_series_identification: AttrV<DocumentId>,
59    /// Cost type.
60    #[serde(rename = "BusinessType")]
61    pub business_type: AttrV<CostBusinessType>,
62    /// Direction (optional — absent for startup/fixed costs).
63    #[serde(rename = "Direction", default, skip_serializing_if = "Option::is_none")]
64    pub direction: Option<AttrV<Direction>>,
65    /// Product (always active power `8716867000016`).
66    #[serde(rename = "Product")]
67    pub product: AttrV<Product>,
68    /// Control zone of the resource (optional).
69    #[serde(
70        rename = "ConnectingArea",
71        default,
72        skip_serializing_if = "Option::is_none"
73    )]
74    pub connecting_area: Option<ControlZoneRef>,
75    /// Resource object identifier (BDEW resource code, NDE scheme; optional).
76    #[serde(
77        rename = "ResourceObject",
78        default,
79        skip_serializing_if = "Option::is_none"
80    )]
81    pub resource_object: Option<ResourceObjectRef>,
82    /// Quarter-hour cost data for the delivery day.
83    #[serde(rename = "Period")]
84    pub period: Period,
85}
86
87// ── Kostenblatt ───────────────────────────────────────────────────────────────
88
89/// `Kostenblatt` — cost sheet for redispatch billing between grid operators.
90///
91/// XSD version: 1.0d (Fehlerkorrektur 2025-04-16)  
92/// No XML namespace.
93///
94/// Contains energy-dependent and fixed cost data for each activated
95/// controllable resource in a given delivery day.
96#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
97#[serde(rename = "Kostenblatt")]
98pub struct Kostenblatt {
99    /// Unique document identifier (max 35 chars).
100    #[serde(rename = "DocumentIdentification")]
101    pub document_identification: AttrV<DocumentId>,
102    /// Document version number (1–999).
103    #[serde(rename = "DocumentVersion")]
104    pub document_version: AttrV<DocumentVersion>,
105    /// Document type (always `Z05`).
106    #[serde(rename = "DocumentType")]
107    pub document_type: AttrV<KostenblattDocType>,
108    /// Process type (always `A14`).
109    #[serde(rename = "ProcessType")]
110    pub process_type: AttrV<KostenblattProcessType>,
111    /// Sender's market participant identifier.
112    #[serde(rename = "SenderIdentification")]
113    pub sender_identification: AttrVWithScheme<MarketParticipantId>,
114    /// Sender's market role.
115    #[serde(rename = "SenderRole")]
116    pub sender_role: AttrV<MarketRoleType>,
117    /// Receiver's market participant identifier.
118    #[serde(rename = "ReceiverIdentification")]
119    pub receiver_identification: AttrVWithScheme<MarketParticipantId>,
120    /// Receiver's market role.
121    #[serde(rename = "ReceiverRole")]
122    pub receiver_role: AttrV<MarketRoleType>,
123    /// Document creation timestamp (UTC, second precision).
124    #[serde(rename = "DocumentDateTime")]
125    pub document_date_time: AttrV<UtcDateTime>,
126    /// Delivery period covered (UTC interval).
127    #[serde(rename = "TimePeriodCovered")]
128    pub time_period_covered: AttrV<TimeInterval>,
129    /// Cost time series (one or more).
130    #[serde(rename = "CostTimeSeries", default)]
131    pub time_series: Vec<CostTimeSeries>,
132}