| 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<string, OCPPResponseService>(); |
| 7 | protected readonly chargingStation: ChargingStation; |
| 8 | |
| 9 | protected constructor(chargingStation: ChargingStation) { |
| 10 | this.chargingStation = chargingStation; |
| 11 | } |
| 12 | |
| 13 | public static getInstance<T extends OCPPResponseService>(this: new (chargingStation: ChargingStation) => T, chargingStation: ChargingStation): T { |
| 14 | if (!OCPPResponseService.instances.has(chargingStation.id)) { |
| 15 | OCPPResponseService.instances.set(chargingStation.id, new this(chargingStation)); |
| 16 | } |
| 17 | return OCPPResponseService.instances.get(chargingStation.id) as T; |
| 18 | } |
| 19 | |
| 20 | public abstract handleResponse(commandName: RequestCommand, payload: JsonType | string, requestPayload: JsonType): Promise<void>; |
| 21 | } |