"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const UpgradeHelper_1 = require("../helpers/UpgradeHelper");
/**
 * The `sos.management.app` API groups together methods for managing the signageOS application installed on the system.
 *
 * <details>
 *     <summary>App Management Capabilities</summary>
 * 		| Capability | Description |
 * 		|:------------|:-------------|
 * 		| `APP_UPGRADE` | If the signageOS application can upgrade itself to a specific version |
 *
 * 		If you want to check if the device supports this capability, use [`sos.management.supports()`](https://developers.signageos.io/sdk/sos_management/#supports).
 * </details>
 */
class App {
    messagePrefix;
    postMessage;
    /** @internal */
    constructor(messagePrefix, postMessage) {
        this.messagePrefix = messagePrefix;
        this.postMessage = postMessage;
    }
    /**
     * The `getType()` method returns the type of the platform the application is running on.
     *
     * :::info
     * - If you need to get a specific Android brand or Raspberry Pi model, use the `sos.management.firmware.getType()`.
     * - `default` type is always Emulator.
     * :::
     *
     * @returns {Promise<AppType>} Resolves to the type of the application platform.
     * @since 4.0.0
     *
     * @example
     * const appType = await sos.management.app.getType();
     * console.log(appType); // tizen, linux, webos, etc.
     */
    async getType() {
        const { applicationType } = await this.postMessage({
            type: this.getMessage('get_application_type'),
        });
        return applicationType;
    }
    /**
     * The `getVersion()` method returns the version of the Core App that is currently running on the device.
     *
     * @returns {Promise<string>} Resolves to the version of the Core application.
     * @since 4.0.0
     *
     * @example
     * const version = await sos.management.app.getVersion();
     * console.log(`Current application version is: ${version}`); // e.g. '4.0.0', '5.2.1', etc.
     */
    async getVersion() {
        const { applicationVersion } = await this.postMessage({
            type: this.getMessage('get_application_version'),
        });
        return applicationVersion;
    }
    /** @internal */
    async upgrade(arg1, arg2) {
        const { baseUrl, version, directUri } = (0, UpgradeHelper_1.parseUpgradeArguments)(arg1, arg2);
        await this.postMessage({
            type: this.getMessage('app_upgrade'),
            baseUrl,
            version,
            directUri,
        });
    }
    getMessage(name) {
        return this.messagePrefix + '.' + name;
    }
}
exports.default = App;
//# sourceMappingURL=App.js.map