-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransitPolicy.ts
More file actions
76 lines (65 loc) · 2.29 KB
/
Copy pathTransitPolicy.ts
File metadata and controls
76 lines (65 loc) · 2.29 KB
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
import { EventClassification, EventTriggerSource } from "./DeviceEvent";
import { FlapState, MotionSensorState } from "./FrameMetadata";
export interface TransitPolicyRuleCriteria {
eventTriggerSource?: EventTriggerSource | EventTriggerSource[];
eventClassification?: EventClassification | EventClassification[];
rfidCode?: string | string[];
timeRange?: string | string[];
motionSensorState?: MotionSensorState | MotionSensorState[];
flapState?: FlapState | FlapState[];
}
export interface TransitPolicyRuleAction {
lock?: boolean;
sound?: string;
lockoutDuration?: number;
final?: boolean;
}
export interface TransitPolicyUxOnActivate {
sound?: string;
}
export interface TransitPolicyUx {
onActivate?: TransitPolicyUxOnActivate;
}
export class TransitPolicyRule {
criteria?: TransitPolicyRuleCriteria;
action?: TransitPolicyRuleAction;
[key: string]: any; // Allow any additional properties
constructor(initObj: Partial<TransitPolicy> & Record<string, any>) {
this.criteria = initObj.criteria!;
this.action = initObj.action!;
// Assign other properties from initObj to this instance
for (const key in initObj) {
if (initObj.hasOwnProperty(key) && !this.hasOwnProperty(key)) {
this[key] = initObj[key];
}
}
}
}
export class TransitPolicy {
rules: TransitPolicyRule[];
idleLock: boolean;
idleLockBattery: boolean;
ux: TransitPolicyUx;
[key: string]: any; // Allow any additional properties
constructor(initObj: Partial<TransitPolicy> & Record<string, any>) {
this.rules = initObj.rules ?? [];
this.idleLock = initObj.idleLock ?? true;
this.idleLockBattery = initObj.idleLockBattery ?? this.idleLock;
this.ux = {
...(initObj.ux ?? {}),
onActivate: {
...(initObj.ux?.onActivate ?? {}),
sound: initObj.ux?.onActivate?.sound ?? "coin"
}
};
// Assign other properties from initObj to this instance
for (const key in initObj) {
if (initObj.hasOwnProperty(key) && !this.hasOwnProperty(key)) {
this[key] = initObj[key];
}
}
}
toJSON(): Record<string, any> {
return { ...this };
}
}