"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.native.mdc` API groups together methods for controlling Tizen devices using MDC commands.
 *
 * :::warning
 * This API is currently available on Tizen devices only.
 * :::
 *
 * <details>
 *     <summary>MDC Management Capabilities</summary>
 * 		| Capability | Description |
 * 		|:------------|:-------------|
 * 		| `NATIVE_COMMANDS_MDC` | If device supports performing MDC commands |
 *
 * 		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 Mdc {
    messagePrefix;
    postMessage;
    static MESSAGE_PREFIX = 'mdc';
    /** @internal */
    constructor(messagePrefix, postMessage) {
        this.messagePrefix = messagePrefix;
        this.postMessage = postMessage;
    }
    /**
     * The `sendOne()` method sends an MDC command to another Tizen device on the same network or to the localhost.
     *
     * @param ipAddress The IP address of the device to send the command to.
     * @param command The MDC command to send {@link CodesMDC}.
     * @param data The optional data to send with the command.
     * @throws {Error} If the `ipAddress` is not a valid string or if the `command` is not a valid number.
     * @throws {Error} If the `data` is not an array of numbers.
     * @throws {Error} If any error occurs during the command execution.
     * @returns {Promise<IMDCResponse>} MDC response object containing the result of the command execution.
     * @since 6.5.1
     *
     * @example
     * await sos.native.mdc.sendOne('localhost', CodesMDC.BRIGHTNESS_CONTROL);
     * await sos.native.mdc.sendOne('192.168.0.10', CodesMDC.VOLUME_CONTROL, [50]);
     * await sos.native.mdc.sendOne('192.168.0.10', CodesMDC.PICTURE_CONTROL, [0x54, 0x03]);
     *
     * // You can also send custom number if we don't have predefined command in our enum
     * await sos.native.mdc.sendOne('192.168.0.10', 0x01, []);
     */
    async sendOne(ipAddress, command, data) {
        (0, Validate_1.default)({ ipAddress }).required().string();
        (0, Validate_1.default)({ command }).required().number();
        if (typeof data !== 'undefined') {
            (0, Validate_1.default)({ data }).required().array('number');
        }
        if (typeof data === 'undefined') {
            data = [];
        }
        const { commandResponse } = await this.postMessage({
            type: this.getMessage('send_one'),
            ipAddress,
            command,
            data,
        });
        return commandResponse;
    }
    /**
     * The `sendOneRaw()` method sends an MDC command to another Tizen device on the same network or to the localhost,
     * but without explicitly specifying the command.
     *
     * @param ipAddress The IP address of the device to send the command to.
     * @param data The data as array of numbers to send with the command. It can be also empty array.
     * @throws {Error} If the `ipAddress` is not a valid string or if the `command` is not a valid number.
     * @throws {Error} If the `data` is not an array of numbers.
     * @throws {Error} If any error occurs during the command execution.
     * @returns {Promise<IMDCResponse>} MDC response object containing the result of the command execution.
     *
     * @since 6.5.1
     *
     * @example
     * await sos.native.mdc.sendOneRaw('localhost', [0x1B, 0x00, 0x01, 0x74]); // Promise<IMDCResponse>
     *
     * // Example of returned object
     * {
     *     "type": "ACK", // or NACK
     *     "commandType": 4,
     *     "result": 0, // Value what command returned
     * }
     */
    async sendOneRaw(ipAddress, data) {
        (0, Validate_1.default)({ ipAddress }).required().string();
        (0, Validate_1.default)({ data }).required().array('number');
        const { commandResponse } = await this.postMessage({
            type: this.getMessage('send_one_raw'),
            ipAddress,
            data,
        });
        return commandResponse;
    }
    getMessage(name) {
        return this.getMessagePrefix() + '.' + name;
    }
    getMessagePrefix() {
        return this.messagePrefix + '.' + Mdc.MESSAGE_PREFIX;
    }
}
exports.default = Mdc;
//# sourceMappingURL=Mdc.js.map