"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 ITime_1 = require("./ITime");
/**
 * The `sos.management.time` API groups together methods for working with the system time.
 *
 * <details>
 *     <summary>Time Management Capabilities</summary>
 * 		| Capability | Description |
 * 		|:------------|:-------------|
 * 		| `SET_TIME` | If the device can set the system time. |
 * 		| `SET_TIMEZONE` | If the device can set the system timezone. |
 * 		| `GET_TIMEZONE` | If the device can get the system timezone. |
 * 		| `NTP_TIME` | If the device can set the NTP server and system timezone. |
 *
 * 		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 Time {
    messagePrefix;
    postMessage;
    /** @internal */
    constructor(messagePrefix, postMessage) {
        this.messagePrefix = messagePrefix;
        this.postMessage = postMessage;
    }
    /**
     * The `get()` method returns the currently set time from the device.
     *
     * @returns {Promise<IGetTime>} A promise that resolves to the current time with timezone.
     * @throws {Error} If the time cannot be retrieved.
     * @since 4.0.0
     *
     * @example
     * const currentTime = await sos.management.time.get();
     * console.log(`Current time is: ${currentTime.currentDate} in timezone ${currentTime.timezone}`);
     */
    async get() {
        const { currentTimeWithTimezone } = await this.postMessage({
            type: this.getMessage('get_current_time_with_timezone'),
        });
        return currentTimeWithTimezone;
    }
    /** @deprecated Use `setManual(dateTime, timezone)` instead. */
    set(currentDate, timezone) {
        return this.setManual(currentDate, timezone);
    }
    /** @internal */
    async setManual(...args) {
        const [currentDate, timezone] = args;
        if (currentDate instanceof Date) {
            (0, Validate_1.default)({ currentDate }).required().date();
        }
        else {
            (0, Validate_1.default)({ currentDate }).required().object(ITime_1.VDateTime);
        }
        (0, Validate_1.default)({ timezone }).required().string();
        await this.postMessage({
            type: this.getMessage('set_current_time_with_timezone'),
            currentDate,
            timezone,
        });
    }
    /**
     * The `setNTP()` method sets the NTP server and the system timezone.
     *
     * :::warning Setting NTP server and timezone has side effects
     * - **Tizen / WebOS**: After calling this API, display Reboots!
     *   Tizen has a limited set of available timezones. [Read more here](https://docs.signageos.io/hc/en-us/articles/4405381271314-Tizen-Timezones-Limited-List-for-NTP).
     * - **RaspberryPi**: After calling this API, RPi Reboots the backend server, which can take up to 60 seconds! During the reboot, no JS API is
     *   available. **Always wait for Promise resolution.**
     * :::
     *
     * @param ntpServer The NTP server to set.
     * @param timezone The timezone to set.
     * @return {Promise<void>} A promise that resolves when the NTP server and timezone are successfully set.
     * @throws {Error} If `ntpServer` is not a valid string.
     * @throws {Error} If `timezone` is not a valid string.
     * @throws {Error} If the NTP server and timezone cannot be set.
     * @since 4.0.0
     *
     * @example
     * // Set the NTP server to `pool.ntp.org` and timezone to `Europe/Prague`
     * await sos.management.time.setNTP('pool.ntp.org', 'Europe/Prague');
     */
    async setNTP(ntpServer, timezone) {
        (0, Validate_1.default)({ ntpServer }).required().string();
        (0, Validate_1.default)({ timezone }).required().string();
        await this.postMessage({
            type: this.getMessage('set_ntp_time_with_timezone'),
            ntpServer,
            timezone,
        });
    }
    getMessage(name) {
        return this.messagePrefix + '.' + name;
    }
}
exports.default = Time;
//# sourceMappingURL=Time.js.map