"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Validate_1 = __importDefault(require("../Validate/Validate"));
const App_1 = __importDefault(require("./App/App"));
const Audio_1 = __importDefault(require("./Audio/Audio"));
const AutoRecovery_1 = __importDefault(require("./AutoRecovery/AutoRecovery"));
const Debug_1 = __importDefault(require("./Debug/Debug"));
const Firmware_1 = __importDefault(require("./Firmware/Firmware"));
const Network_1 = __importDefault(require("./Network/Network"));
const OS_1 = __importDefault(require("./OS/OS"));
const Package_1 = __importDefault(require("./Package/Package"));
const PeerRecovery_1 = __importDefault(require("./PeerRecovery/PeerRecovery"));
const Power_1 = __importDefault(require("./Power/Power"));
const Proxy_1 = __importDefault(require("./Proxy/Proxy"));
const RemoteControl_1 = __importDefault(require("./RemoteControl/RemoteControl"));
const Screen_1 = __importDefault(require("./Screen/Screen"));
const Security_1 = __importDefault(require("./Security/Security"));
const Time_1 = __importDefault(require("./Time/Time"));
const Wifi_1 = __importDefault(require("./Wifi/Wifi"));
/**
 * The `sos.management` API group provides methods for managing the device. Through this API, things like device firmware,
 * battery status, brightness, network information, remote control, power, time, or volume can be monitored.
 *
 * :::note GitHub Example
 * - [Basic usage of the Management API](https://github.com/signageos/applet-examples/tree/master/examples/management-js-api/basics)
 * - [Getting basic management data](https://github.com/signageos/applet-examples/tree/master/examples/management-js-api/js-management-getters)
 * - [Setting management data](https://github.com/signageos/applet-examples/tree/master/examples/management-js-api/js-management-setters)
 * :::
 *
 * <details>
 *     <summary>Management Capabilities</summary>
 * 		| Capability | Description |
 * 		|:------------|:-------------|
 * 		| `MODEL` | If device can return proper model name |
 * 		| `SERIAL_NUMBER` | If device can return serial number |
 * 		| `BATTERY_STATUS` | If device can return battery status |
 * 		| `TEMPERATURE` | If device can return current temperature |
 * 		| `BRAND` | If device can return manufacturer brand |
 * 		| `FACTORY_RESET` | If device can perform factory reset |
 * 		| `EXTENDED_MANAGEMENT` | If device can return or set extended management URL |
 * 		| `HARDWARE_ACCELERATION` | If device can turn hardware acceleration on or off |
 *
 * 		If you want to check if the device supports those capabilities, use [`sos.management.supports()`](https://developers.signageos.io/sdk/sos_management/#supports).
 * </details>
 */
class Management {
    messagePrefix;
    postMessage;
    static MESSAGE_PREFIX = 'management';
    app;
    os;
    audio;
    debug;
    firmware;
    package;
    power;
    remoteControl;
    screen;
    time;
    network;
    wifi;
    security;
    proxy;
    autoRecovery;
    peerRecovery;
    /** @internal */
    constructor(messagePrefix, postMessage) {
        this.messagePrefix = messagePrefix;
        this.postMessage = postMessage;
        this.app = new App_1.default(this.getMessagePrefix(), this.postMessage);
        this.os = new OS_1.default(this.getMessagePrefix(), this.postMessage);
        this.audio = new Audio_1.default(this.getMessagePrefix(), this.postMessage);
        this.debug = new Debug_1.default(this.getMessagePrefix(), this.postMessage);
        this.firmware = new Firmware_1.default(this.getMessagePrefix(), this.postMessage);
        this.package = new Package_1.default(this.getMessagePrefix(), this.postMessage);
        this.power = new Power_1.default(this.getMessagePrefix(), this.postMessage);
        this.remoteControl = new RemoteControl_1.default(this.getMessagePrefix(), this.postMessage);
        this.screen = new Screen_1.default(this.getMessagePrefix(), this.postMessage);
        this.time = new Time_1.default(this.getMessagePrefix(), this.postMessage);
        this.network = new Network_1.default(this.getMessagePrefix(), this.postMessage);
        this.wifi = new Wifi_1.default(this.getMessagePrefix(), this.postMessage);
        this.security = new Security_1.default(this.getMessagePrefix(), this.postMessage);
        this.proxy = new Proxy_1.default(this.getMessagePrefix(), this.postMessage);
        this.autoRecovery = new AutoRecovery_1.default(this.getMessagePrefix(), this.postMessage);
        this.peerRecovery = new PeerRecovery_1.default(this.getMessagePrefix(), this.postMessage);
    }
    /**
     * The `supports()` method determines whether a queried capability is supported.
     *
     * #### What are capabilities?
     * Capabilities are features or functionalities that a device can support. We divided those capabilities into `front` and `management` capabilities.
     * This section is about management capabilities, which include features to manage the device, receive information about the device, or change its settings.
     *
     * On the other hand, the `front` capabilities are features that are related to the application running on the device, such as displaying content, handling user input, etc.
     * To check `front` capabilities, refer to the `sos.display.supports()` method or [this section](https://developers.signageos.io/sdk/sos/display#supports).
     *
     * :::tip
     * If you want to check specific capabilities, refer to the sidebar for the selected management section. Every section has its capabilities written in the description,
     * or check the **ManagementCapability** type in `supports()` method. It has a list of all available capabilities for all platforms.
     * :::
     *
     * @param capability The capability to check for support.
     * @returns {Promise<boolean>} A promise that resolves to `true` if the capability is supported, otherwise `false`.
     * @throws {Error} If the capability is not a valid string.
     * @since 2.0.0
     *
     * @example
     * const isSupported = await sos.management.supports('OS_VERSION');
     * console.log(`Is OS_VERSION supported? ${isSupported}`);
     */
    async supports(capability) {
        (0, Validate_1.default)({ capability }).required().string();
        const { supports } = await this.postMessage({
            type: this.getMessage('supports'),
            capability,
        });
        return supports;
    }
    /**
     * The `getModel()` method returns the model of the device.
     *
     * @returns {Promise<string>} A promise that resolves to the model name of the device.
     * @since 2.0.0
     *
     * @example
     * const model = await sos.management.getModel();
     * console.log(`Device model is: ${model}`); // e.g. 'XC4055' (BrightSign)
     */
    async getModel() {
        const { model } = await this.postMessage({
            type: this.getMessage('get_model'),
        });
        return model;
    }
    /**
     * The `getSerialNumber()` method returns the serial number of the device.
     *
     * @returns {Promise<string>} A promise that resolves to the serial number of the device.
     * @since 2.1.0
     *
     * @example
     * const serialNumber = await sos.management.getSerialNumber();
     * console.log(`Device serial number is: ${serialNumber}`); // e.g. '1234567890'
     */
    async getSerialNumber() {
        const { serialNumber } = await this.postMessage({
            type: this.getMessage('get_serial_number'),
        });
        return serialNumber;
    }
    /** @deprecated Use `sos.management.network.listInterfaces()` instead. */
    async getNetworkInfo() {
        return await this.network.getActiveInfo();
    }
    /**
     * The `getBatteryStatus()` method returns information about the battery of the device.
     *
     * :::note
     * - Emulator has mocked this method and will always return a battery status with 100% charge.
     * :::
     *
     * @returns {Promise<IBatteryStatus>} A promise that resolves to an object containing the battery status.
     * @throws {Error} If the device does not support battery status monitoring.
     * @since 2.1.0
     *
     * @example
     * const batteryStatus = await sos.management.getBatteryStatus();
     * console.log(`Battery status: ${batteryStatus.percentage}% charged`);
     */
    async getBatteryStatus() {
        const { batteryStatus } = await this.postMessage({
            type: this.getMessage('get_battery_status'),
        });
        return batteryStatus;
    }
    /**
     * The `getTemperature()` method returns the temperature of the device (in the 0-100 range of degrees Celsius).
     *
     * @returns {Promise<number>} A promise that resolves to the current temperature of the device.
     * @throws {Error} If the device does not support temperature monitoring.
     * @since 3.0.0
     *
     * @example
     * const temperature = await sos.management.getTemperature();
     * console.log(`Current device temperature is: ${temperature}°C`); // e.g. 25°C
     */
    async getTemperature() {
        const { currentTemperature } = await this.postMessage({
            type: this.getMessage('get_current_temperature'),
        });
        return currentTemperature;
    }
    /**
     * The `getBrand()` method returns the manufacturer brand of the device.
     *
     * @returns {Promise<string>} A promise that resolves to the brand name of the device.
     * @throws {Error} If the device does not support brand information.
     * @since 5.7.0
     *
     * @example
     * const brand = await sos.management.getBrand();
     * console.log(`Device brand is: ${brand}`); // e.g., 'Samsung', 'LG', BrightSign, etc.
     */
    async getBrand() {
        const { brand } = await this.postMessage({
            type: this.getMessage('get_brand'),
        });
        return brand;
    }
    /**
     * The `resetSettings()` method initializes the reset of the specific device settings.
     *
     * :::warning
     * This is currently only implemented on the Linux platform.
     * :::
     *
     * @returns {Promise<void>} A promise that resolves when the settings are reset.
     * @throws {Error} If the device does not support settings reset.
     * @since 4.0.0
     */
    async resetSettings() {
        await this.postMessage({
            type: this.getMessage('reset_settings'),
        });
    }
    /**
     * The `factoryReset()` method initializes the factory reset of the device.
     *
     * @returns {Promise<void>} A promise that resolves when the factory reset is initiated.
     * @throws {Error} If the device does not support factory reset.
     * @since 4.0.0
     */
    async factoryReset() {
        await this.postMessage({
            type: this.getMessage('factory_reset'),
        });
    }
    /**
     * The `getExtendedManagementUrl()` method returns the management URL of the device.
     *
     * :::info
     * This is currently only implemented for the MagicInfo on the Tizen platform.
     * :::
     *
     * @returns {Promise<string | null>} A promise that resolves to the management URL of the device, or `null` if not set.
     * @throws {Error} If the device does not support the extended management URL.
     * @since 6.2.0
     */
    async getExtendedManagementUrl() {
        const { url } = await this.postMessage({
            type: this.getMessage('get_extendedmanagement_url'),
        });
        return url;
    }
    /**
     * The `getExtendedManagementUrl()` sets the management URL of the device.
     *
     * :::info
     * This is currently only implemented for the MagicInfo on the Tizen platform.
     * :::
     *
     * @param url The management URL to set. If `null`, it will remove the current URL.
     * @returns {Promise<void>} A promise that resolves when the URL is set.
     * @throws {Error} If the URL is not a valid string or if the device
     * @throws {Error} If the device does not support the extended management URL.
     * @since 6.2.0
     *
     * @example
     * await sos.management.setExtendedManagementUrl('https://example.com/management');
     * // later
     * const url = await sos.management.getExtendedManagementUrl();
     * console.log(`Extended management URL is: ${url}`); // e.g. 'https://example.com/management'
     */
    async setExtendedManagementUrl(url) {
        (0, Validate_1.default)({ url }).string().canBeNull();
        await this.postMessage({
            type: this.getMessage('set_extendedmanagement_url'),
            url,
        });
    }
    /**
     * The `setHardwareAcceleration()` method turns hardware acceleration on or off.
     *
     * :::note
     * - This is currently only implemented for the BrightSign platform.
     * - Device must always be rebooted for the changes to take effect.
     * :::
     *
     * @param enabled Whether hardware acceleration should be enabled.
     * @returns {Promise<void>} A promise that resolves when the hardware acceleration setting is applied.
     * @throws {Error} If the `enabled` parameter is not a boolean.
     * @throws {Error} If the device does not support hardware acceleration management.
     * @since 7.1.0
     *
     * @example
     * await sos.management.setHardwareAcceleration(true).then(async () => {
     * 	console.log('Hardware acceleration enabled.');
     * 	await sos.management.reboot();
     * }).catch((error) => {
     * 	console.error('Failed to set hardware acceleration:', error);
     * });
     */
    async setHardwareAcceleration(enabled) {
        (0, Validate_1.default)({ enabled }).required().boolean();
        await this.postMessage({
            type: this.getMessage('set_hardware_acceleration'),
            enabled,
        });
    }
    /**
     * The `isHardwareAccelerationEnabled()` method returns whether hardware acceleration is enabled.
     *
     * @returns {Promise<boolean>} A promise that resolves to `true` if hardware acceleration is enabled, otherwise `false`.
     * @throws {Error} If the device does not support hardware acceleration management.
     * @since 7.1.0
     *
     * @example
     * const isEnabled = await sos.management.isHardwareAccelerationEnabled();
     * console.log(`Hardware acceleration is ${isEnabled ? 'enabled' : 'disabled'}.`);
     */
    async isHardwareAccelerationEnabled() {
        const { enabled } = await this.postMessage({
            type: this.getMessage('is_hardware_acceleration_enabled'),
        });
        return enabled;
    }
    getMessage(name) {
        return this.getMessagePrefix() + '.' + name;
    }
    getMessagePrefix() {
        return this.messagePrefix + '.' + Management.MESSAGE_PREFIX;
    }
}
exports.default = Management;
//# sourceMappingURL=Management.js.map