-import ChargingStation from '../ChargingStation';
import { JsonType } from '../../types/JsonType';
import { RequestCommand } from '../../types/ocpp/Requests';
+import type ChargingStation from '../ChargingStation';
export default abstract class OCPPResponseService {
- protected chargingStation: ChargingStation;
+ private static instance: OCPPResponseService | null = null;
- constructor(chargingStation: ChargingStation) {
- this.chargingStation = chargingStation;
+ protected constructor() {
+ // This is intentional
}
- public abstract handleResponse(commandName: RequestCommand, payload: JsonType | string, requestPayload: JsonType): Promise<void>;
+ public static getInstance<T extends OCPPResponseService>(this: new () => T): T {
+ if (!OCPPResponseService.instance) {
+ OCPPResponseService.instance = new this();
+ }
+ return OCPPResponseService.instance as T;
+ }
+
+ public abstract responseHandler(
+ chargingStation: ChargingStation,
+ commandName: RequestCommand,
+ payload: JsonType,
+ requestPayload: JsonType
+ ): Promise<void>;
}