grid_tariffs/
price_list.rs1use chrono::NaiveDate;
2use serde::Serialize;
3
4use crate::{
5 FeedInRevenueSimplified, Money, TransferFeeSimplified,
6 costs::Cost,
7 helpers,
8 power_tariffs::{PowerTariff, PowerTariffSimplified},
9 revenues::FeedInRevenue,
10 transfer_fee::TransferFee,
11};
12
13#[derive(Debug, Clone, Serialize)]
14#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
15pub struct PriceList {
16 variant: Option<&'static str>,
17 from_date: NaiveDate,
18 monthly_fee: Cost,
20 monthly_production_fee: Cost,
22 transfer_fee: TransferFee,
23 feed_in_revenue: FeedInRevenue,
24 power_tariff: PowerTariff,
25}
26
27impl PriceList {
28 pub(crate) const fn builder() -> PriceListBuilder {
29 PriceListBuilder::new()
30 }
31
32 pub const fn variant(&self) -> Option<&'static str> {
33 self.variant
34 }
35
36 pub const fn from_date(&self) -> NaiveDate {
37 self.from_date
38 }
39
40 pub const fn monthly_fee(&self) -> &Cost {
41 &self.monthly_fee
42 }
43
44 pub const fn monthly_production_fee(&self) -> &Cost {
45 &self.monthly_production_fee
46 }
47
48 pub const fn transfer_fee(&self) -> &TransferFee {
49 &self.transfer_fee
50 }
51
52 pub const fn feed_in_revenue(&self) -> &FeedInRevenue {
53 &self.feed_in_revenue
54 }
55
56 pub const fn power_tariff(&self) -> &PowerTariff {
57 &self.power_tariff
58 }
59
60 pub fn simplified(&self, fuse_size: u16, yearly_consumption: u32) -> PriceListSimplified {
61 PriceListSimplified::new(self, fuse_size, yearly_consumption)
62 }
63}
64
65#[derive(Debug, Clone)]
66pub(crate) struct PriceListBuilder {
67 variant: Option<&'static str>,
68 from_date: Option<NaiveDate>,
69 monthly_fee: Option<Cost>,
71 monthly_production_fee: Option<Cost>,
73 transfer_fee: Option<TransferFee>,
74 feed_in_revenue: Option<FeedInRevenue>,
75 power_tariff: Option<PowerTariff>,
76}
77
78impl PriceListBuilder {
79 pub(crate) const fn new() -> Self {
80 Self {
81 variant: None,
82 from_date: None,
83 monthly_fee: None,
84 monthly_production_fee: None,
85 transfer_fee: None,
86 feed_in_revenue: None,
87 power_tariff: None,
88 }
89 }
90
91 pub(crate) const fn build(self) -> PriceList {
92 PriceList {
93 variant: self.variant,
94 from_date: self.from_date.expect("`from_date` required"),
95 monthly_fee: self.monthly_fee.expect("`monthly_fee` required"),
96 monthly_production_fee: self
97 .monthly_production_fee
98 .expect("`monthly_production_fee` required"),
99 transfer_fee: self.transfer_fee.expect("`transfer_fee` required"),
100 feed_in_revenue: self.feed_in_revenue.expect("`feed_in_revenue` required"),
101 power_tariff: self.power_tariff.expect("`grid_tariff` required"),
102 }
103 }
104
105 pub(crate) const fn variant(mut self, name: &'static str) -> Self {
106 self.variant = Some(name);
107 self
108 }
109
110 pub(crate) const fn from_date(mut self, year: i32, month: u32, day: u32) -> Self {
111 self.from_date = Some(helpers::date(year, month, day));
112 self
113 }
114
115 pub(crate) const fn monthly_fee(mut self, monthly_fee: Cost) -> Self {
116 self.monthly_fee = Some(monthly_fee);
117 self
118 }
119
120 pub(crate) const fn monthly_production_fee(mut self, monthly_production_fee: Cost) -> Self {
121 self.monthly_production_fee = Some(monthly_production_fee);
122 self
123 }
124
125 pub(crate) const fn transfer_fee(mut self, transfer_fee: TransferFee) -> Self {
126 self.transfer_fee = Some(transfer_fee);
127 self
128 }
129
130 pub(crate) const fn feed_in_revenue(mut self, feed_in_revenue: FeedInRevenue) -> Self {
131 self.feed_in_revenue = Some(feed_in_revenue);
132 self
133 }
134
135 pub(crate) const fn power_tariff(mut self, power_tariff: PowerTariff) -> Self {
136 self.power_tariff = Some(power_tariff);
137 self
138 }
139}
140
141#[derive(Debug, Clone, Serialize)]
142#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
143pub struct PriceListSimplified {
144 variant: Option<&'static str>,
145 fuse_size: u16,
146 yearly_consumption_based: bool,
148 from_date: NaiveDate,
149 monthly_fee: Option<Money>,
151 monthly_production_fee: Option<Money>,
153 transfer_fee: TransferFeeSimplified,
154 feed_in_revenue: FeedInRevenueSimplified,
155 power_tariff: PowerTariffSimplified,
156}
157
158impl PriceListSimplified {
159 fn new(pl: &PriceList, fuse_size: u16, yearly_consumption: u32) -> Self {
160 Self {
161 variant: pl.variant,
162 fuse_size,
163 yearly_consumption_based: pl.monthly_fee.is_yearly_consumption_based(fuse_size)
164 || pl
165 .monthly_production_fee
166 .is_yearly_consumption_based(fuse_size)
167 || pl.transfer_fee.is_yearly_consumption_based(fuse_size),
168 from_date: pl.from_date,
169 monthly_fee: pl.monthly_fee.cost_for(fuse_size, yearly_consumption),
170 monthly_production_fee: pl
171 .monthly_production_fee
172 .cost_for(fuse_size, yearly_consumption),
173 transfer_fee: pl.transfer_fee.simplified(fuse_size, yearly_consumption),
174 feed_in_revenue: pl.feed_in_revenue.simplified(fuse_size, yearly_consumption),
175 power_tariff: pl.power_tariff.simplified(fuse_size, yearly_consumption),
176 }
177 }
178}