/**
 * invoke.ts — platform entry wrappers for non-HTTP invocations.
 *
 * Cron, queue, and DO handlers construct DB + services once per invocation
 * through these helpers instead of importing legacy constructors directly.
 */

import type { MultidealEnv } from '@/server/env.js';
import type { DoDbClient } from '@/server/do-host/lib/db.js';
import { buildServices } from './bundle.js';
import type { Services } from './types.js';
import { createScheduledDbService, warmDb, type DbServiceEnv } from './db.js';

/** Construct and warm the scheduled-context DB client for one invocation. */
export async function createScheduledInvocationDb(env: DbServiceEnv): Promise<DoDbClient> {
  const db = createScheduledDbService(env);
  await warmDb(db);
  return db;
}

/** Build the full services bundle for one cron/queue/DO invocation (no HTTP request). */
export async function buildInvocationServices(env: MultidealEnv): Promise<Services> {
  return buildServices(env);
}
