-import type ChargingStation from '../ChargingStation';
-import { HandleErrorParams } from '../../types/Error';
-import { IncomingRequestCommand } from '../../types/ocpp/Requests';
-import { JsonType } from '../../types/JsonType';
-import logger from '../../utils/Logger';
-
-export default abstract class OCPPIncomingRequestService {
- private static readonly instances: Map<string, OCPPIncomingRequestService> = new Map<string, OCPPIncomingRequestService>();
- protected chargingStation: ChargingStation;
-
- protected constructor(chargingStation: ChargingStation) {
- this.chargingStation = chargingStation;
+import { EventEmitter } from 'node:events'
+
+import _Ajv, { type ValidateFunction } from 'ajv'
+import _ajvFormats from 'ajv-formats'
+
+import { type ChargingStation, getIdTagsFile } from '../../charging-station/index.js'
+import { OCPPError } from '../../exception/index.js'
+import type {
+ ClearCacheResponse,
+ HandleErrorParams,
+ IncomingRequestCommand,
+ JsonType,
+ OCPPVersion
+} from '../../types/index.js'
+import { logger, setDefaultErrorParams } from '../../utils/index.js'
+import { OCPPConstants } from './OCPPConstants.js'
+import { OCPPServiceUtils } from './OCPPServiceUtils.js'
+type Ajv = _Ajv.default
+// eslint-disable-next-line @typescript-eslint/no-redeclare
+const Ajv = _Ajv.default
+const ajvFormats = _ajvFormats.default
+
+const moduleName = 'OCPPIncomingRequestService'
+
+export abstract class OCPPIncomingRequestService extends EventEmitter {
+ private static instance: OCPPIncomingRequestService | null = null
+ private readonly version: OCPPVersion
+ protected readonly ajv: Ajv
+ protected abstract payloadValidateFunctions: Map<
+ IncomingRequestCommand,
+ ValidateFunction<JsonType>
+ >
+
+ protected constructor (version: OCPPVersion) {
+ super()
+ this.version = version
+ this.ajv = new Ajv({
+ keywords: ['javaType'],
+ multipleOfPrecision: 2
+ })
+ ajvFormats(this.ajv)
+ this.incomingRequestHandler = this.incomingRequestHandler.bind(this)
+ this.validateIncomingRequestPayload = this.validateIncomingRequestPayload.bind(this)