import { getTenantId } from "@devlego/backend-core/tenancy"
import { getAllApps } from "@devlego/backend-core/db"
import { quotas, QuotaUsageType, StaticQuotaName } from "@devlego/pro"

export const run = async () => {
  // get app count
  // @ts-ignore
  const devApps = await getAllApps({ dev: true })
  const appCount = devApps ? devApps.length : 0

  // sync app count
  const tenantId = getTenantId()
  console.log(`[Tenant: ${tenantId}] Syncing app count: ${appCount}`)
  await quotas.setUsage(appCount, StaticQuotaName.APPS, QuotaUsageType.STATIC)
}
