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

import NevisMobileAuthentication

class PasswordChangeOperation: Operation {
	// MARK: Properties

	var state: OperationState
	var onError: ErrorHandler
	let onSuccess: () -> ()
	let passwordChanger: PasswordChanger

	// MARK: Initialization

	init(operationId: String) {
		self.state = NoOperationState()
		self.onError = { OnErrorImpl(operationId: operationId, method: .passwordChange).onError($0) }
		self.onSuccess = { OnSuccessImpl(operationId: operationId, method: .passwordChange).onSuccess() }
		self.passwordChanger = PasswordChangerImpl(operationId: operationId)
	}

	// MARK: Operation

	func cancel() {
		state.cancel()
	}

	// MARK: Public Interface

	func update(state: PasswordChangeOperationState) -> PasswordChangeOperation {
		self.state = state
		return self
	}
}
