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

import type { PasswordEnrollmentContext } from './PasswordEnrollmentContext';
import type { PasswordEnrollmentHandler } from './PasswordEnrollmentHandler';
import { PasswordPolicyProvider } from './PasswordPolicyProvider';

/**
 * The object in charge of password enrollment.
 *
 * The SDK does not provide implementations of this interface.
 * The implementation must be done by the user of the SDK.
 *
 * @see
 * - {@link Registration.passwordEnroller}
 * - {@link AuthCloudApiRegistration.passwordEnroller}
 * - {@link OutOfBandRegistration.passwordEnroller}
 */
export abstract class PasswordEnroller extends PasswordPolicyProvider {
	/**
	 * The method that will be invoked till either the user provides a password
	 * that is conform with the format specified by the {@link PasswordPolicy} or till
	 * the operation is cancelled (through the {@link PasswordEnrollmentHandler.cancel}).
	 *
	 * @param context the object providing some contextual information during password enrollment.
	 * @param handler the object that must be invoked with the new password.
	 */
	abstract enrollPassword(
		context: PasswordEnrollmentContext,
		handler: PasswordEnrollmentHandler
	): void;

	/**
	 * This method is invoked when valid password credentials were provided during registration.
	 *
	 * This method can be used for instance to hide the UI used to ask for credentials to the user
	 * (some text fields to get password credentials) and then display some progress message indicating
	 * that the operation is ongoing.
	 *
	 * Note that invoking this method does not mean that the registration completed successfully
	 * (this is notified through `onSuccess` methods once the FIDO UAF server validates the request
	 * generated with the credentials).
	 */
	abstract onValidCredentialsProvided(): void;
}
