Apply dependencies update
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPResponseService.ts
1 import type ChargingStation from '../ChargingStation';
2 import { JsonType } from '../../types/JsonType';
3 import { RequestCommand } from '../../types/ocpp/Requests';
4
5 export default abstract class OCPPResponseService {
6 private static readonly instances: Map<string, OCPPResponseService> = new Map<
7 string,
8 OCPPResponseService
9 >();
10
11 protected readonly chargingStation: ChargingStation;
12
13 protected constructor(chargingStation: ChargingStation) {
14 this.chargingStation = chargingStation;
15 }
16
17 public static getInstance<T extends OCPPResponseService>(
18 this: new (chargingStation: ChargingStation) => T,
19 chargingStation: ChargingStation
20 ): T {
21 if (!OCPPResponseService.instances.has(chargingStation.id)) {
22 OCPPResponseService.instances.set(chargingStation.id, new this(chargingStation));
23 }
24 return OCPPResponseService.instances.get(chargingStation.id) as T;
25 }
26
27 public abstract handleResponse(
28 commandName: RequestCommand,
29 payload: JsonType | string,
30 requestPayload: JsonType
31 ): Promise<void>;
32 }