"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"));
/**
 * The `sos.management.audio` API groups methods for managing audio settings.
 *
 * <details>
 *     <summary>Volume Management Capabilities</summary>
 * 		| Capability | Description |
 * 		|:------------|:-------------|
 * 		| `SET_VOLUME` | If device can set volume level |
 * 		| `GET_VOLUME` | If device can get current volume level |
 *
 * 		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 Audio {
    messagePrefix;
    postMessage;
    /** @internal */
    constructor(messagePrefix, postMessage) {
        this.messagePrefix = messagePrefix;
        this.postMessage = postMessage;
    }
    /**
     * The `getVolume()` method returns the current volume level of the device.
     *
     * @returns {Promise<number>} A promise that resolves to the current volume level, which is a value between 0 and 100.
     * @since 2.0.0
     *
     * @example
     * const currentVolume = await sos.management.audio.getVolume();
     * console.log(`Current volume level is: ${currentVolume}`); // e.g. 75
     */
    async getVolume() {
        const { volume } = await this.postMessage({
            type: this.getMessage('get_volume'),
        });
        return volume;
    }
    /**
     * The `setVolume()` method sets the volume level of the device.
     *
     * @param volume Value between 0 and 100.
     * @returns {Promise<void>} A promise that resolves when the volume is set.
     * @throws {Error} If the volume is not a number or is outside the range of 0 to 100.
     * @since 2.0.0
     *
     * @example // {@link https://github.com/signageos/applet-examples/tree/master/examples/management-js-api/volume | Example applet with setting volume}
     *
     * @example
     * await sos.management.audio.setVolume(50);
     */
    async setVolume(volume) {
        (0, Validate_1.default)({ volume }).required().number().min(0).max(100);
        await this.postMessage({
            type: this.getMessage('set_volume'),
            volume,
        });
    }
    getMessage(name) {
        return this.messagePrefix + '.' + name;
    }
}
exports.default = Audio;
//# sourceMappingURL=Audio.js.map