This repository has been archived by the owner on Feb 10, 2024. It is now read-only.
/
JokerComApiDomainPrice.ts
88 lines (81 loc) · 3.36 KB
/
JokerComApiDomainPrice.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2022. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.
import { explainJokerComApiDomainPeriod, isJokerComApiDomainPeriod, JokerComApiDomainPeriod } from "./JokerComApiDomainPeriod";
import { explainJokerComApiCurrency, isJokerComApiCurrency, JokerComApiCurrency } from "./JokerComApiCurrency";
import { explainJokerComApiPriceAmount, isJokerComApiPriceAmount, JokerComApiPriceAmount } from "./JokerComApiPriceAmount";
import { explain, explainProperty } from "../../../../types/explain";
import { explainBooleanOrUndefined, isBooleanOrUndefined } from "../../../../types/Boolean";
import { explainStringOrUndefined, isStringOrUndefined } from "../../../../types/String";
import { explainRegularObject, isRegularObject } from "../../../../types/RegularObject";
import { explainNoOtherKeys, hasNoOtherKeys } from "../../../../types/OtherKeys";
export interface JokerComApiDomainPrice {
readonly price : JokerComApiPriceAmount;
readonly currency : JokerComApiCurrency;
readonly period : JokerComApiDomainPeriod;
readonly isPromo ?: boolean;
readonly promoStart ?: string;
readonly promoEnd ?: string;
}
export function createJokerComApiDomainPrice (
price : JokerComApiPriceAmount,
currency : JokerComApiCurrency,
period : JokerComApiDomainPeriod,
isPromo : boolean | undefined,
promoStart : string | undefined,
promoEnd : string | undefined
) : JokerComApiDomainPrice {
return {
price,
currency,
period,
isPromo,
promoStart,
promoEnd
};
}
export function isJokerComApiDomainPrice (value: any) : value is JokerComApiDomainPrice {
return (
isRegularObject(value)
&& hasNoOtherKeys(value, [
'price',
'currency',
'period',
'isPromo',
'promoStart',
'promoEnd'
])
&& isJokerComApiPriceAmount(value?.price)
&& isJokerComApiCurrency(value?.currency)
&& isJokerComApiDomainPeriod(value?.period)
&& isBooleanOrUndefined(value?.isPromo)
&& isStringOrUndefined(value?.promoStart)
&& isStringOrUndefined(value?.promoEnd)
);
}
export function explainJokerComApiDomainPrice (value: any) : string {
return explain(
[
explainRegularObject(value),
explainNoOtherKeys(value, [
'price',
'currency',
'period',
'isPromo',
'promoStart',
'promoEnd'
]),
explainProperty("price", explainJokerComApiPriceAmount(value?.price)),
explainProperty("currency", explainJokerComApiCurrency(value?.currency)),
explainProperty("period", explainJokerComApiDomainPeriod(value?.period)),
explainProperty("isPromo", explainBooleanOrUndefined(value?.isPromo)),
explainProperty("promoStart", explainStringOrUndefined(value?.promoStart)),
explainProperty("promoEnd", explainStringOrUndefined(value?.promoEnd))
]
);
}
export function stringifyJokerComApiDomainPrice (value : JokerComApiDomainPrice) : string {
return `JokerComApiDomainPrice(${value})`;
}
export function parseJokerComApiDomainPrice (value: any) : JokerComApiDomainPrice | undefined {
if (isJokerComApiDomainPrice(value)) return value;
return undefined;
}