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

import NevisMobileAuthentication

protocol MethodHandler {
	func execute(using client: MobileAuthenticationClient, method: ReactMethod, with message: ChannelInMessage) async
}

extension MethodHandler {
	func validate<T>(message: ChannelInMessage) -> T {
		guard message is T else {
			fatalError("Wrong type of message received!")
		}

		return message as! T
	}

	func validate<T>(state: OperationState) -> T {
		guard state is T else {
			fatalError("Operation state is missing or not \(String(describing: T.self))!")
		}

		return state as! T
	}
}
