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

import NevisMobileAuthentication

struct PinsChangeMethodHandler: MethodHandler {
	func execute(using _: MobileAuthenticationClient, method: ReactMethod, with message: ChannelInMessage) async {
		let message: PinsChangeMessage = validate(message: message)
		let operation: PinChangeOperation = await OperationCache.shared.read(by: message.operationId)
		let state: PinChangeState = await validate(state: operation.state)
		await state.changePin(oldPin: message.oldPin.joined(), newPin: message.newPin.joined())
		MethodChannelHandler.shared.resolve(method: method)
	}
}
