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

import { OperationMessage } from './OperationMessage';
import { PinPolicyMessage } from './PinPolicyMessage';
import { PinPolicy } from '../../../operations/pin/PinPolicy';

/**
 * Holds the parameters of the PIN change operation call.
 */
export class PinChangeMessage extends OperationMessage {
	/**
	 * The identifier of the operation.
	 */
	operationId: string;

	/**
	 * Flag that tells whether the PIN changer is provided.
	 */
	pinChangerProvided: boolean;

	/**
	 * The username.
	 */
	username?: string;

	/**
	 * Specifies the PIN policy to be used.
	 */
	pinPolicyMessage?: PinPolicyMessage;

	/**
	 * Flag that tells whether the success callback is provided.
	 */
	onSuccessProvided: boolean;

	/**
	 * Flag that tells whether the error callback is provided.
	 */
	onErrorProvided: boolean;

	/**
	 * Default constructor for {@link PinChangeMessage}.
	 *
	 * @param operationId the identifier of the operation.
	 * @param pinChangerProvided flag that tells whether the PIN changer is provided.
	 * @param onSuccessProvided flag that tells whether the success callback is provided.
	 * @param onErrorProvided flag that tells whether the error callback is provided.
	 * @param username the username.
	 * @param pinPolicy specifies the PIN policy to be used.
	 */
	constructor(
		operationId: string,
		pinChangerProvided: boolean,
		onSuccessProvided: boolean,
		onErrorProvided: boolean,
		username?: string,
		pinPolicy?: PinPolicy
	) {
		super();
		this.operationId = operationId;
		this.username = username;
		this.pinChangerProvided = pinChangerProvided;
		this.onSuccessProvided = onSuccessProvided;
		this.onErrorProvided = onErrorProvided;

		if (pinPolicy) {
			this.pinPolicyMessage = new PinPolicyMessage(
				operationId,
				pinPolicy.minLength,
				pinPolicy.maxLength
			);
		}
	}
}
