-
Notifications
You must be signed in to change notification settings - Fork 2
/
ocpi.tariff.ts
60 lines (53 loc) · 1.57 KB
/
ocpi.tariff.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { z } from "zod";
import { DisplayText } from "./ocpi.common";
import { EnergyMix } from "./ocpi.location";
const TariffDimensionType = z.enum(["ENERGY", "FLAT", "PARKING_TIME", "TIME"]);
const PriceComponent = z.object({
type: TariffDimensionType,
price: z.number().nonnegative(),
step_size: z.number().int().nonnegative(),
});
const DayOfWeek = z.enum([
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY",
"SATURDAY",
"SUNDAY",
]);
const TariffRestrictions = z.object({
start_time: z
.string()
.length(5)
.regex(/[0-2][0-9]:[0-5][0-9]/)
.nullish(),
end_time: z
.string()
.length(5)
.regex(/[0-2][0-9]:[0-5][0-9]/)
.nullish(),
start_date: z.string().length(10).nullish(),
end_date: z.string().length(10).nullish(),
min_kwh: z.number().nonnegative().nullish(),
max_kwh: z.number().nonnegative().nullish(),
min_power: z.number().nonnegative().nullish(),
max_power: z.number().nonnegative().nullish(),
min_duration: z.number().nonnegative().nullish(),
max_duration: z.number().nonnegative().nullish(),
day_of_week: DayOfWeek.nullish(),
});
const TariffElement = z.object({
price_components: z.array(PriceComponent).nonempty(),
restrictions: TariffRestrictions.nullish(),
});
export const Tariff = z.object({
id: z.string().max(36),
currency: z.string().length(3),
tariff_alt_text: z.array(DisplayText).nullish(),
tariff_alt_url: z.string().url().nullish(),
elements: z.array(TariffElement).nonempty(),
energy_mix: EnergyMix.nullish(),
last_updated: z.date(),
});
export const Tariffs = z.array(Tariff);