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

import { PasswordEnrollmentContext } from '../../../operations/password/PasswordEnrollmentContext';
import { ChannelMessage } from '../ChannelMessage';

/**
 * Holds the parameters of the enroll password call.
 */
export class PasswordEnrollerMessage extends ChannelMessage {
	/**
	 * The identifier of the operation.
	 */
	operationId: string;

	/**
	 * The password enrollment context.
	 */
	context: PasswordEnrollmentContext;

	/**
	 * Default constructor for {@link PasswordEnrollerMessage}.
	 *
	 * @param operationId the identifier of the operation.
	 * @param context the password enrollment context.
	 */
	private constructor(operationId: string, context: PasswordEnrollmentContext) {
		super();
		this.operationId = operationId;
		this.context = context;
	}

	/**
	 * Alternate constructor that creates an {@link PasswordEnrollerMessage} from a json.
	 *
	 * @param json contains the source for instance creation.
	 * @returns the created instance.
	 */
	static fromJson(json: any): PasswordEnrollerMessage {
		const operationId = json.operationId;
		const context = PasswordEnrollmentContext.fromJson(json.context);

		return new PasswordEnrollerMessage(operationId, context);
	}
}
