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

import { ChannelMessage } from '../ChannelMessage';

/**
 * Holds the parameters of the validate PIN call.
 */
export class PinValidationMessage extends ChannelMessage {
	/**
	 * The identifier of the operation.
	 */
	operationId: string;

	/**
	 * The PIN to be validated.
	 */
	pin: string;

	/**
	 * Default constructor for {@link PinValidationMessage}.
	 *
	 * @param operationId the identifier of the operation.
	 * @param pin the PIN to be validated.
	 */
	private constructor(operationId: string, pin: string) {
		super();
		this.operationId = operationId;
		this.pin = pin;
	}

	/**
	 * Alternate constructor that creates an {@link PinValidationMessage} from a json.
	 *
	 * @param json contains the source for instance creation.
	 * @returns the created instance.
	 */
	static fromJson(json: any): PinValidationMessage {
		return new PinValidationMessage(json.operationId, json.pin.join(''));
	}
}
