Skip to main content

redispatch_xml/documents/
kostenblatt.rs

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