"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const semver_1 = __importDefault(require("semver"));
const apps_1 = require("../apps");
const getAppsCatalogForDevice_1 = require("../device/use-cases/getAppsCatalogForDevice");
const isUpdateAvailable = async (deviceInfo, appAndVersion, checkMustUpdate = true) => {
    const applicationsByDevice = await (0, getAppsCatalogForDevice_1.getAppsCatalogForDevice)(deviceInfo);
    const appAvailableInProvider = applicationsByDevice.find(({ versionName: name }) => appAndVersion.name === name);
    if (!appAvailableInProvider)
        return false;
    if (!checkMustUpdate) {
        return semver_1.default.gt(appAvailableInProvider.version, appAndVersion.version);
    }
    return (!!appAvailableInProvider &&
        !(0, apps_1.mustUpgrade)(appAvailableInProvider.versionName, appAvailableInProvider.version));
};
exports.default = isUpdateAvailable;
//# sourceMappingURL=isUpdateAvailable.js.map