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

import NevisMobileAuthentication

struct PinValidatedForPinChangeMethodHandler: MethodHandler {
	func execute(using _: MobileAuthenticationClient, method: ReactMethod, with message: ChannelInMessage) async {
		let message: PinValidatedForPinChangeMessage = validate(message: message)
		let operation: PinChangeOperation = await OperationCache.shared.read(by: message.operationId)
		let state: PinValidateForPinChangeState = await validate(state: operation.state)
		await state.validatePin(errorMessage: message.errorMessage, cause: message.cause)
		MethodChannelHandler.shared.resolve(method: method)
	}
}
