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

import { Version } from './Version';

/**
 * The object containing information about the
 * native iOS Nevis Mobile Authentication SDK.
 */
export abstract class IOSMetaData {
	/**
	 * The current version of the Nevis Mobile Authentication SDK.
	 */
	abstract mobileAuthenticationVersion: Version;

	/**
	 * The FacetId used by the Nevis Mobile Authentication SDK.
	 */
	abstract applicationFacetId: string;

	/**
	 * Default constructor for {@link IOSMetaData}.
	 *
	 * @param mobileAuthenticationVersion the current version of the Nevis Mobile Authentication SDK.
	 * @param applicationFacetId the FacetId used by the Nevis Mobile Authentication SDK.
	 * @returns an {@link IOSMetaData} instance.
	 */
	static create(mobileAuthenticationVersion: Version, applicationFacetId: string): IOSMetaData {
		return new IOSMetaDataImpl(mobileAuthenticationVersion, applicationFacetId);
	}

	/**
	 * Alternate constructor that creates a {@link IOSMetaData} from a json.
	 *
	 * @param json contains the source for instance creation.
	 * @returns a {@link IOSMetaData} instance.
	 */
	static fromJson(json: any): IOSMetaData {
		return IOSMetaDataImpl.fromJson(json);
	}
}

export class IOSMetaDataImpl extends IOSMetaData {
	mobileAuthenticationVersion: Version;
	applicationFacetId: string;

	constructor(mobileAuthenticationVersion: Version, applicationFacetId: string) {
		super();
		this.mobileAuthenticationVersion = mobileAuthenticationVersion;
		this.applicationFacetId = applicationFacetId;
	}

	static fromJson(json: any): IOSMetaDataImpl {
		const mobileAuthenticationVersion = Version.fromJson(json.mobileAuthenticationVersion);

		return new IOSMetaDataImpl(mobileAuthenticationVersion, json.applicationFacetId);
	}
}
