import {NativeModules} from 'react-native';

// @ts-ignore Check whether __turboModuleProxy exists, it may not
const isTurboModuleEnabled = global.__turboModuleProxy != null;

const DynamsoftLicenseModule = isTurboModuleEnabled ?
    require("./NativeDynamsoftLicenseModule").default : NativeModules.DynamsoftLicenseModule;

/**
 * The LicenseManager class provides a set of APIs to manage the licensing for the Dynamsoft Capture Vision architecture.
 * @hideconstructor
 * */
export class LicenseManager {

    /**
     * Initializes the license for the application using a license key.
     * <p>Code Snippet:</p>
     *
     * ```
     * LicenseManager.initLicense('your-license-key').then(() => {
     *      //Init license successfully.
     * }).catch(error => {
     *      console.error("Init license failed.", error);
     * });
     * ```
     *
     * @param license - The license key to be used for initialization.
     * @return Promise<void> - A promise that resolves when initLicense successfully or rejects an error when failed.
     * */
    static initLicense(license: string): Promise<void> {
        return DynamsoftLicenseModule.initLicense(license)
    }

    /**
     * Sets a friendly name for the device, which can be used for easier identification in license management.
     * @param name - The friendly name to be set for the device.
     * */
    static setDeviceFriendlyName(name: string) {
        DynamsoftLicenseModule.setDeviceFriendlyName(name)
    }

    /**
     * Retrieves the unique identifier (UUID) of the device, which is often used in license management to associate licenses with specific devices.
     * @return Promise<string> - A promise that resolves with the device UUID as a string.
     * */
    static getDeviceUUID(): Promise<string> {
        return DynamsoftLicenseModule.getDeviceUUID()
    }
}
