1use chrono::NaiveDate;
2use serde::Serialize;
3
4use crate::{Money, helpers::date};
5
6pub(crate) static SE_TAXES: &[Tax] = &[
7 Tax::new(
8 "Energiskatt",
9 Money::from_inner(54875),
10 TaxAppliedBy::KwhConsumed,
11 date(2025, 1, 1),
12 Some(date(2025, 12, 31)),
13 ),
14 Tax::new(
15 "Energiskatt",
16 Money::from_inner(44995),
17 TaxAppliedBy::KwhConsumed,
18 date(2026, 1, 1),
19 None,
20 ),
21];
22
23#[derive(Debug, Clone, Copy, Serialize)]
24#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
25pub enum TaxAppliedBy {
26 KwhConsumed,
27}
28
29#[derive(Debug, Clone, Copy, Serialize)]
30#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
31pub struct Tax {
32 description: &'static str,
33 cost: Money,
34 applied_by: TaxAppliedBy,
35 from_date: NaiveDate,
36 to_date: Option<NaiveDate>,
38}
39
40impl Tax {
41 pub(crate) const fn new(
42 description: &'static str,
43 cost: Money,
44 applied_by: TaxAppliedBy,
45 from_date: NaiveDate,
46 to_date: Option<NaiveDate>,
47 ) -> Self {
48 Self {
49 description,
50 cost,
51 applied_by,
52 from_date,
53 to_date,
54 }
55 }
56
57 pub(crate) fn valid_for(&self, today: NaiveDate) -> bool {
58 today >= self.from_date && self.to_date.is_none_or(|to_date| today <= to_date)
59 }
60}