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

import NevisMobileAuthentication

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

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