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

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

/**
 * Holds the parameters of the metaData native event.
 */
export class MetaDataInMessage extends ChannelMessage {
	/**
	 * The identifier of the operation.
	 */
	operationId: string;

	/**
	 * The metaData information.
	 */
	metaData: MetaData;

	/**
	 * Default constructor for {@link MetaDataInMessage}.
	 *
	 * @param operationId the identifier of the operation.
	 * @param metaData the metaData.
	 */
	private constructor(operationId: string, metaData: MetaData) {
		super();
		this.operationId = operationId;
		this.metaData = metaData;
	}

	/**
	 * Alternate constructor that creates a {@link MetaDataInMessage} from a json.
	 *
	 * @param json contains the source for instance creation.
	 * @returns the created instance.
	 */
	static fromJson(json: any): MetaDataInMessage {
		const operationId = json.operationId;
		const data = json;
		const metaData: MetaData = data && MetaData.fromJson(data);

		return new MetaDataInMessage(operationId, metaData);
	}
}
