"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = void 0;
const tenancy_1 = require("@devlego/backend-core/tenancy");
const db_1 = require("@devlego/backend-core/db");
const pro_1 = require("@devlego/pro");
const run = () => __awaiter(void 0, void 0, void 0, function* () {
    // get app count
    const opts = { dev: false };
    const prodApps = yield (0, db_1.getAllApps)(opts);
    const prodAppCount = prodApps ? prodApps.length : 0;
    // sync app count
    const tenantId = (0, tenancy_1.getTenantId)();
    console.log(`[Tenant: ${tenantId}] Syncing published app count: ${prodAppCount}`);
    yield pro_1.quotas.setUsage(prodAppCount, pro_1.StaticQuotaName.PUBLISHED_APPS, pro_1.QuotaUsageType.STATIC);
});
exports.run = run;
