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

import NevisMobileAuthentication

struct PasswordsChangeMethodHandler: MethodHandler {
	func execute(using _: MobileAuthenticationClient, method: ReactMethod, with message: ChannelInMessage) async {
		let message: PasswordsChangeMessage = validate(message: message)
		let operation: PasswordChangeOperation = await OperationCache.shared.read(by: message.operationId)
		let state: PasswordChangeState = await validate(state: operation.state)
		await state.change(password: message.oldPassword.joined(), newPassword: message.newPassword.joined())
		MethodChannelHandler.shared.resolve(method: method)
	}
}
