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

import NevisMobileAuthentication

final class OnSuccessImpl: Sendable {
	// MARK: Properties

	let operationId: String
	let method: ReactMethod

	// MARK: Initialization

	init(operationId: String, method: ReactMethod) {
		self.operationId = operationId
		self.method = method
	}
}

// MARK: - Public Interface

extension OnSuccessImpl {
	func onSuccess(data: (some Any)?) {
		let message = OnSuccessMessage(operationId: operationId, data: data)
		Task {
			MethodChannelHandler.shared.resolve(method: method, message: message)
			await OperationCache.shared.delete(by: operationId)
		}
	}
}
