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

import NevisMobileAuthentication

protocol Operation: Sendable {
	var state: OperationState { get async }

	func cancel() async
}

extension Operation {
	func cancel() async {
		await state.cancel()
	}
}

// MARK: -

protocol StandardOperation: Operation {
	associatedtype T

	typealias SuccessHandler = @Sendable (T?) -> ()
	typealias ErrorHandler = @Sendable (MobileAuthenticationClientError) -> ()

	var onSuccess: SuccessHandler { get async }
	var onError: ErrorHandler { get async }
}

// MARK: -

protocol ResultOperation: Operation {
	associatedtype T

	typealias ResultHandler = @Sendable (T) -> ()

	var onResult: ResultHandler { get async }
}
