"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const UpgradeHelper_1 = require("../helpers/UpgradeHelper");
/**
 * The `sos.management.firmware` API groups together methods for working with the firmware of the device.
 *
 * :::warning
 * Always check if your absolute firmware URL ends with a firmware file. Example: `https://cnd.your-cms.com/brightsign/fw/brightsign-update.bsfw`
 * :::
 *
 * :::info
 * For BrightSign firmware upgrade, please ensure that you have a text file with the SHA1 hash of that firmware file.
 * - Firmware file path: `https://cnd.your-cms.com/brightsign/fw/brightsign-update.bsfw`
 * - SHA1 txt file: `https://cnd.your-cms.com/brightsign/fw/brightsign-update.bsfw.sha1.txt`
 * :::
 *
 * <details>
 *     <summary>Firmware Management Capabilities</summary>
 * 		| Capability | Description |
 * 		|:------------|:-------------|
 * 		| `FIRMWARE_UPGRADE` | If device can upgrade firmware 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 Firmware {
    messagePrefix;
    postMessage;
    /** @internal */
    constructor(messagePrefix, postMessage) {
        this.messagePrefix = messagePrefix;
        this.postMessage = postMessage;
    }
    /** @internal */
    async upgrade(arg1, arg2) {
        const { baseUrl, version, directUri } = (0, UpgradeHelper_1.parseUpgradeArguments)(arg1, arg2);
        await this.postMessage({
            type: this.getMessage('firmware_upgrade'),
            baseUrl,
            version,
            directUri,
        });
    }
    /**
     * The `getVersion()` method returns the version of the firmware currently installed on the device.
     *
     * @returns {Promise<string>} A promise that resolves to the current firmware version.
     * @since 4.0.0
     *
     * @example
     * const version = await sos.management.firmware.getVersion();
     * console.log(version); // Returns String e.g. T-HKMLAKUC-2020.5
     */
    async getVersion() {
        const { firmwareVersion } = await this.postMessage({
            type: this.getMessage('get_firmware_version'),
        });
        return firmwareVersion;
    }
    /**
     * The `getType()` method returns the type of the firmware currently installed on the device.
     *
     * This information, when combined with firmware version, can be used to identify a correct firmware image to install on the current device.
     *
     * <details>
     *     <summary>Linux and Android prefixes</summary>
     * 		| Type | Description |
     * 		|:------------|:-------------|
     * 		| `rpi` | Any Raspberry Pi 3 or Compute Module 3 |
     * 		| `rpi4` | Any Raspberry Pi 4 or Compute Module 4 |
     * 		| `benq-` | Any Benq display |
     * 		| `philips-` | Any Philips display |
     * 		| `sharp-` | Any Sharp display |
     * 		| `elo-` | Any Elo display |
     * </details>
     *
     * @returns {Promise<string>} A promise that resolves to the current firmware type.
     * @since 4.8.0
     *
     * @example
     * const type = await sos.management.firmware.getType();
     * console.log(type); // e.g. rpi4
     */
    async getType() {
        const { firmwareType } = await this.postMessage({
            type: this.getMessage('get_firmware_type'),
        });
        return firmwareType;
    }
    getMessage(name) {
        return this.messagePrefix + '.' + name;
    }
}
exports.default = Firmware;
//# sourceMappingURL=Firmware.js.map