grid_tariffs/
power_tariffs.rs1use chrono::DateTime;
2use chrono_tz::Tz;
3use serde::Serialize;
4
5use crate::{
6 Language, Money,
7 costs::{CostPeriods, CostPeriodsSimple, LoadType},
8};
9
10#[derive(Debug, Clone, Serialize)]
11#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
12pub enum PowerTariff {
13 Unverified,
14 NotImplemented,
15 Periods {
16 method: TariffCalculationMethod,
17 periods: CostPeriods,
18 },
19}
20
21impl PowerTariff {
22 pub const fn is_unverified(&self) -> bool {
23 matches!(self, Self::Unverified)
24 }
25
26 pub(super) const fn new(method: TariffCalculationMethod, periods: CostPeriods) -> Self {
27 Self::Periods { method, periods }
28 }
29
30 pub fn simplified(
31 &self,
32 fuse_size: u16,
33 yearly_consumption: u32,
34 language: Language,
35 ) -> PowerTariffSimplified {
36 PowerTariffSimplified::new(self, fuse_size, yearly_consumption, language)
37 }
38}
39
40#[derive(Debug, Clone, Copy, Serialize)]
42#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
43pub enum TariffCalculationMethod {
44 AverageDays(u8),
46 AverageHours(u8),
48}
49
50#[derive(Debug, Clone, Serialize)]
52#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
53pub enum PowerTariffSimplified {
54 Unverified,
55 NotImplemented,
56 Periods {
57 method: TariffCalculationMethod,
58 periods: CostPeriodsSimple,
59 },
60}
61
62impl PowerTariffSimplified {
63 fn new(fee: &PowerTariff, fuse_size: u16, yearly_consumption: u32, language: Language) -> Self {
64 match *fee {
65 PowerTariff::Unverified => PowerTariffSimplified::Unverified,
66 PowerTariff::NotImplemented => PowerTariffSimplified::NotImplemented,
67 PowerTariff::Periods { method, periods } => PowerTariffSimplified::Periods {
68 method,
69 periods: CostPeriodsSimple::new(periods, fuse_size, yearly_consumption, language),
70 },
71 }
72 }
73}