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