//
// Copyright © 2024 Nevis Security AG. All rights reserved.
//

import NevisMobileAuthentication

private func executeVerifyUserBehavior(operationId: String, context: UserVerificationContext, userInteractionState: UserInteractionState) {
	let operation: UserInteractionOperation = OperationCache.shared.read(by: operationId)
	OperationCache.shared.update(by: operationId, operation: operation.update(state: userInteractionState))
	let message = UserVerifierMessage(operationId: operationId, context: context)
	EventEmitter.shared.dispatch(event: .verifyUser, message: message)
}

extension BiometricUserVerifier {
	func verifyBiometric(operationId: String, context: UserVerificationContext, userInteractionState: UserInteractionState) {
		executeVerifyUserBehavior(operationId: operationId, context: context, userInteractionState: userInteractionState)
	}
}

extension DevicePasscodeUserVerifier {
	func verifyDevicePasscode(operationId: String, context: UserVerificationContext, userInteractionState: UserInteractionState) {
		executeVerifyUserBehavior(operationId: operationId, context: context, userInteractionState: userInteractionState)
	}
}

extension PinUserVerifier {
	func verifyPin(operationId: String, context: UserVerificationContext, userInteractionState: UserInteractionState) {
		executeVerifyUserBehavior(operationId: operationId, context: context, userInteractionState: userInteractionState)
	}
}

extension PasswordUserVerifier {
	func verifyPassword(operationId: String, context: UserVerificationContext, userInteractionState: UserInteractionState) {
		executeVerifyUserBehavior(operationId: operationId, context: context, userInteractionState: userInteractionState)
	}
}
