use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub enum CalculationMethod {
#[serde(rename = "STUFEN")]
Steps,
#[serde(rename = "ZONEN")]
Zones,
#[serde(rename = "VORZONEN_GP")]
PreZoneBasePrice,
#[serde(rename = "SIGMOID")]
Sigmoid,
#[serde(rename = "BLINDARBEIT_GT_50_PROZENT")]
ReactivePowerAbove50Percent,
#[serde(rename = "BLINDARBEIT_GT_40_PROZENT")]
ReactivePowerAbove40Percent,
#[serde(rename = "BLINDARBEIT_MIT_FREIMENGE")]
ReactivePowerWithFreeAllowance,
#[serde(rename = "AP_GP_ZONEN")]
WorkingAndBasePriceZoned,
#[serde(rename = "LP_INSTALL_LEISTUNG")]
CapacityChargeInstalledCapacity,
#[serde(rename = "AP_TRANSPORT_ODER_VERTEILNETZ")]
WorkingPriceTransportOrDistribution,
#[serde(rename = "AP_TRANSPORT_ODER_VERTEILNETZ_ORTSVERTEILNETZ_SIGMOID")]
WorkingPriceTransportOrDistributionLocalSigmoid,
#[serde(rename = "LP_JAHRESVERBRAUCH")]
CapacityChargeAnnualConsumption,
#[serde(rename = "LP_TRANSPORT_ODER_VERTEILNETZ")]
CapacityPriceTransportOrDistribution,
#[serde(rename = "LP_TRANSPORT_ODER_VERTEILNETZ_ORTSVERTEILNETZ_SIGMOID")]
CapacityPriceTransportOrDistributionLocalSigmoid,
#[serde(rename = "FUNKTIONEN")]
Functions,
#[serde(rename = "VERBRAUCH_UEBER_SLP_GRENZE_FUNKTIONSBEZOGEN_WEITERE_BERECHNUNG_ALS_LGK")]
ConsumptionAboveSLPThresholdFunctionBasedLGK,
}
impl CalculationMethod {
pub fn german_name(&self) -> &'static str {
match self {
Self::Steps => "Stufen",
Self::Zones => "Zonen",
Self::PreZoneBasePrice => "Vorzonengrundpreis",
Self::Sigmoid => "Sigmoid",
Self::ReactivePowerAbove50Percent => "Blindarbeit oberhalb 50% der Wirkarbeit",
Self::ReactivePowerAbove40Percent => "Blindarbeit oberhalb 40% der Wirkarbeit",
Self::ReactivePowerWithFreeAllowance => "Blindarbeit mit Freimenge",
Self::WorkingAndBasePriceZoned => "Arbeits- und Grundpreis gezont",
Self::CapacityChargeInstalledCapacity => {
"Leistungsentgelt auf Grundlage der installierten Leistung"
}
Self::WorkingPriceTransportOrDistribution => {
"AP auf Grundlage Transport- oder Verteilnetz"
}
Self::WorkingPriceTransportOrDistributionLocalSigmoid => {
"AP auf Grundlage Transport- oder Verteilnetz, Ortsverteilnetz über Sigmoid"
}
Self::CapacityChargeAnnualConsumption => {
"Leistungsentgelt auf Grundlage des Jahresverbrauchs"
}
Self::CapacityPriceTransportOrDistribution => {
"LP auf Grundlage Transport- oder Verteilnetz"
}
Self::CapacityPriceTransportOrDistributionLocalSigmoid => {
"LP auf Grundlage Transport- oder Verteilnetz, Ortsverteilnetz über Sigmoid"
}
Self::Functions => "Funktionen",
Self::ConsumptionAboveSLPThresholdFunctionBasedLGK => {
"Verbrauch über SLP-Grenze funktionsbezogen als LGK"
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_serialize() {
assert_eq!(
serde_json::to_string(&CalculationMethod::Steps).unwrap(),
r#""STUFEN""#
);
assert_eq!(
serde_json::to_string(&CalculationMethod::Zones).unwrap(),
r#""ZONEN""#
);
}
#[test]
fn test_deserialize() {
assert_eq!(
serde_json::from_str::<CalculationMethod>(r#""SIGMOID""#).unwrap(),
CalculationMethod::Sigmoid
);
}
#[test]
fn test_roundtrip() {
for method in [
CalculationMethod::Steps,
CalculationMethod::Zones,
CalculationMethod::PreZoneBasePrice,
CalculationMethod::Sigmoid,
CalculationMethod::ReactivePowerAbove50Percent,
CalculationMethod::ReactivePowerAbove40Percent,
CalculationMethod::ReactivePowerWithFreeAllowance,
CalculationMethod::WorkingAndBasePriceZoned,
CalculationMethod::CapacityChargeInstalledCapacity,
CalculationMethod::WorkingPriceTransportOrDistribution,
CalculationMethod::WorkingPriceTransportOrDistributionLocalSigmoid,
CalculationMethod::CapacityChargeAnnualConsumption,
CalculationMethod::CapacityPriceTransportOrDistribution,
CalculationMethod::CapacityPriceTransportOrDistributionLocalSigmoid,
CalculationMethod::Functions,
CalculationMethod::ConsumptionAboveSLPThresholdFunctionBasedLGK,
] {
let json = serde_json::to_string(&method).unwrap();
let parsed: CalculationMethod = serde_json::from_str(&json).unwrap();
assert_eq!(method, parsed);
}
}
}