"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.package` API groups together methods for installing custom Android packages.
 *
 * <details>
 *     <summary>Package Management Capabilities</summary>
 * 		| Capability | Description |
 * 		|:------------|:-------------|
 * 		| `PACKAGE_INSTALL` | If device supports installing packages |
 * 		| `STOP_PACKAGE` | If device supports stopping packages |
 *
 * 		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 Package {
    messagePrefix;
    postMessage;
    /** @internal */
    constructor(messagePrefix, postMessage) {
        this.messagePrefix = messagePrefix;
        this.postMessage = postMessage;
    }
    /**
     * The `install()` method installs a particular package from the specified URL.
     *
     * @param baseUrl URL where the package is available
     * @param packageName Name of the Android package
     * @param version Package version
     * @param build If relevant for your device
     * @returns {Promise<void>} A promise that resolves when the package is successfully installed.
     * @throws {Error} If `baseUrl` is not a valid URL
     * @throws {Error} If `packageName` is not a string
     * @throws {Error} If `version` is not a string
     * @throws {Error} If `build` is not a string or null
     */
    async install(baseUrl, packageName, version, build) {
        (0, Validate_1.default)({ baseUrl }).required().uri();
        (0, Validate_1.default)({ packageName }).required().string();
        (0, Validate_1.default)({ version }).required().string();
        (0, Validate_1.default)({ build }).canBeNull().required().string();
        await this.postMessage({
            type: this.getMessage('install_package'),
            baseUrl,
            packageName,
            version,
            build,
        });
    }
    /**
     * The `stop()` method stops a certain package.
     *
     * @param packageName Name of the android package
     *
     * @returns {Promise<boolean>} Resolves to `true` if the package was stopped, `false` if the package was already stopped before.
     * @since 8.2.0
     */
    async stop(packageName) {
        (0, Validate_1.default)({ packageName }).required().string();
        const { stopped } = await this.postMessage({
            type: this.getMessage('stop_package'),
            packageName,
        });
        return stopped;
    }
    getMessage(name) {
        return this.messagePrefix + '.' + name;
    }
}
exports.default = Package;
//# sourceMappingURL=Package.js.map