"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ErrorCodes_1 = __importDefault(require("../../Error/ErrorCodes"));
const Validate_1 = __importDefault(require("../../Validate/Validate"));
/**
 * The `sos.hardware.led` API groups together methods for controlling LEDs of the device.
 *
 * :::warning
 * This is currently only supported by Phillips devices.
 * :::
 */
class Led {
    messagePrefix;
    postMessage;
    static MESSAGE_PREFIX = 'led';
    /** @internal */
    constructor(messagePrefix, postMessage) {
        this.messagePrefix = messagePrefix;
        this.postMessage = postMessage;
    }
    /**
     * The `setColor()` methods sets the LED color.
     *
     * @param color The color to set the LED to, in hexadecimal format (e.g. `#FF0000` for red). If `null`, it will turn off the LED.
     * @returns {Promise<void>} Returns a promise that resolves when the color is successfully set.
     * @throws {Error} If the color is not a valid hexadecimal string or is not a string at all.
     * @throws {Error} If the LED cannot be controlled by the device.
     * @throws {Error} If any other error occurs while setting the color.
     * @since 4.4.0
     *
     * @example
     * // Set the LED color to red
     * await sos.hardware.led.setColor('#FF0000');
     * // Turn off the LED
     * await sos.hardware.led.setColor(null);
     */
    async setColor(color) {
        this.checkColorValidity(color);
        await this.postMessage({
            type: this.getMessage('set_color'),
            color: color ? color.toUpperCase() : null,
        });
    }
    checkColorValidity(color) {
        (0, Validate_1.default)({ color }).canBeNull().string(null, ErrorCodes_1.default.HARDWARE_LED_COLOR_IS_NOT_STRING);
        (0, Validate_1.default)({ color })
            .canBeNull()
            .matchRegExp(/^#[0-9A-Fa-f]{6,6}$/, ErrorCodes_1.default.HARDWARE_LED_COLOR_IS_NOT_VALID);
    }
    getMessage(name) {
        return this.messagePrefix + '.' + Led.MESSAGE_PREFIX + '.' + name;
    }
}
exports.default = Led;
//# sourceMappingURL=Led.js.map