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

import { Version } from './Version';

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

	/**
	 * Gives back the SHA-256 hash of the signing certificate of the application
	 * that includes the Nevis Mobile Authentication SDK.
	 */
	abstract signingCertificateSha256: string;

	/**
	 * Default constructor for {@link AndroidMetaData}.
	 *
	 * @param mobileAuthenticationVersion the current version of the Nevis Mobile Authentication SDK.
	 * @param signingCertificateSha256 the SHA-256 hash of the signing certificate of the application.
	 * @returns an {@link AndroidMetaData} instance.
	 */
	static create(
		mobileAuthenticationVersion: Version,
		signingCertificateSha256: string
	): AndroidMetaData {
		return new AndroidMetaDataImpl(mobileAuthenticationVersion, signingCertificateSha256);
	}

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

export class AndroidMetaDataImpl extends AndroidMetaData {
	mobileAuthenticationVersion: Version;
	signingCertificateSha256: string;

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

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

		return new AndroidMetaDataImpl(mobileAuthenticationVersion, json.signingCertificateSha256);
	}
}
