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

import NevisMobileAuthentication

struct OutOfBandAuthenticationMethodHandler: MethodHandler {
	func execute(using _: MobileAuthenticationClient, method: ReactMethod, with message: ChannelInMessage) async {
		let message: OutOfBandAuthenticationMessage = validate(message: message)
		let operation: OutOfBandAuthenticationOperation = await OperationCache.shared.read(by: message.operationId)
		await operation.update(operationId: message.operationId, method: method)

		let authentication = operation.authentication.configure(by: message, operation: operation)
		await OperationCache.shared.update(by: message.operationId, operation: operation)
		authentication.execute()
	}
}
