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

import NevisMobileAuthentication

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

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