-import { AuthorizeResponse, StartTransactionResponse, StopTransactionReason, StopTransactionResponse } from '../../types/ocpp/Transaction';
-import { DiagnosticsStatus, IncomingRequestCommand, RequestCommand, ResponseType, SendParams } from '../../types/ocpp/Requests';
-
-import { BootNotificationResponse } from '../../types/ocpp/Responses';
-import { ChargePointErrorCode } from '../../types/ocpp/ChargePointErrorCode';
-import { ChargePointStatus } from '../../types/ocpp/ChargePointStatus';
-import type ChargingStation from '../ChargingStation';
-import Constants from '../../utils/Constants';
-import { ErrorType } from '../../types/ocpp/ErrorType';
-import { HandleErrorParams } from '../../types/Error';
-import { JsonType } from '../../types/JsonType';
-import { MessageType } from '../../types/ocpp/MessageType';
-import { MeterValue } from '../../types/ocpp/MeterValues';
-import OCPPError from '../../exception/OCPPError';
-import type OCPPResponseService from './OCPPResponseService';
-import PerformanceStatistics from '../../performance/PerformanceStatistics';
-import Utils from '../../utils/Utils';
-import logger from '../../utils/Logger';
-
-export default abstract class OCPPRequestService {
- private static readonly instances: Map<string, OCPPRequestService> = new Map<string, OCPPRequestService>();
- protected readonly chargingStation: ChargingStation;
- private readonly ocppResponseService: OCPPResponseService;
-
- protected constructor(chargingStation: ChargingStation, ocppResponseService: OCPPResponseService) {
- this.chargingStation = chargingStation;
- this.ocppResponseService = ocppResponseService;
+import _Ajv, { type ValidateFunction } from 'ajv'
+import _ajvFormats from 'ajv-formats'
+
+import type { ChargingStation } from '../../charging-station/index.js'
+import { OCPPError } from '../../exception/index.js'
+import { PerformanceStatistics } from '../../performance/index.js'
+import {
+ ChargingStationEvents,
+ type ErrorCallback,
+ type ErrorResponse,
+ ErrorType,
+ type IncomingRequestCommand,
+ type JsonType,
+ MessageType,
+ type OCPPVersion,
+ type OutgoingRequest,
+ RequestCommand,
+ type RequestParams,
+ type Response,
+ type ResponseCallback,
+ type ResponseType
+} from '../../types/index.js'
+import {
+ clone,
+ formatDurationMilliSeconds,
+ handleSendMessageError,
+ logger
+} from '../../utils/index.js'
+import { OCPPConstants } from './OCPPConstants.js'
+import type { OCPPResponseService } from './OCPPResponseService.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 = 'OCPPRequestService'
+
+const defaultRequestParams: RequestParams = {
+ skipBufferingOnError: false,
+ triggerMessage: false,
+ throwError: false
+}
+
+export abstract class OCPPRequestService {
+ private static instance: OCPPRequestService | null = null
+ private readonly version: OCPPVersion
+ private readonly ocppResponseService: OCPPResponseService
+ protected readonly ajv: Ajv
+ protected abstract payloadValidateFunctions: Map<RequestCommand, ValidateFunction<JsonType>>
+
+ protected constructor (version: OCPPVersion, ocppResponseService: OCPPResponseService) {
+ this.version = version
+ this.ajv = new Ajv({
+ keywords: ['javaType'],
+ multipleOfPrecision: 2
+ })
+ ajvFormats(this.ajv)
+ this.ocppResponseService = ocppResponseService
+ this.requestHandler = this.requestHandler.bind(this)
+ this.sendMessage = this.sendMessage.bind(this)
+ this.sendResponse = this.sendResponse.bind(this)
+ this.sendError = this.sendError.bind(this)
+ this.internalSendMessage = this.internalSendMessage.bind(this)
+ this.buildMessageToSend = this.buildMessageToSend.bind(this)
+ this.validateRequestPayload = this.validateRequestPayload.bind(this)
+ this.validateIncomingRequestResponsePayload =
+ this.validateIncomingRequestResponsePayload.bind(this)