grid_tariffs/
power_tariffs.rs

1use serde::Serialize;
2
3use crate::{
4    Language,
5    costs::{CostPeriods, CostPeriodsSimple},
6};
7
8#[derive(Debug, Clone, Serialize)]
9#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
10pub enum PowerTariff {
11    Unverified,
12    NotImplemented,
13    Periods {
14        method: TariffCalculationMethod,
15        periods: CostPeriods,
16    },
17}
18
19impl PowerTariff {
20    pub const fn is_unverified(&self) -> bool {
21        matches!(self, Self::Unverified)
22    }
23
24    pub(super) const fn new(method: TariffCalculationMethod, periods: CostPeriods) -> Self {
25        Self::Periods { method, periods }
26    }
27
28    pub fn simplified(
29        &self,
30        fuse_size: u16,
31        yearly_consumption: u32,
32        language: Language,
33    ) -> PowerTariffSimplified {
34        PowerTariffSimplified::new(self, fuse_size, yearly_consumption, language)
35    }
36}
37
38/// The method used to calculate power tariffs
39#[derive(Debug, Clone, Copy, Serialize)]
40#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
41pub enum TariffCalculationMethod {
42    /// Power peak for top hour of the top x days of the month
43    AverageDays(u8),
44    /// Average of top x hours of the month
45    AverageHours(u8),
46}
47
48/// Like PowerTariff, but with costs being simple Money objects
49#[derive(Debug, Clone, Serialize)]
50#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
51pub enum PowerTariffSimplified {
52    Unverified,
53    NotImplemented,
54    Periods {
55        method: TariffCalculationMethod,
56        periods: CostPeriodsSimple,
57    },
58}
59
60impl PowerTariffSimplified {
61    fn new(fee: &PowerTariff, fuse_size: u16, yearly_consumption: u32, language: Language) -> Self {
62        match *fee {
63            PowerTariff::Unverified => PowerTariffSimplified::Unverified,
64            PowerTariff::NotImplemented => PowerTariffSimplified::NotImplemented,
65            PowerTariff::Periods { method, periods } => PowerTariffSimplified::Periods {
66                method,
67                periods: CostPeriodsSimple::new(periods, fuse_size, yearly_consumption, language),
68            },
69        }
70    }
71}