import { env } from "../../../env.js";
import { createLocalWorld } from "@workflow/world-local";
import { createWorld } from "@workflow/world-postgres";
import { createVercelWorld } from "@workflow/world-vercel";

//#region src/domains/evals/workflow/world.ts
/**
* Workflow world configuration.
*
* Static imports are required instead of dynamic imports because
* Vercel's NFT can't trace dynamic imports in bundled code.
*
* Set WORKFLOW_TARGET_WORLD to: 'local' | 'vercel' | '@workflow/world-postgres'
* Defaults to 'local' for development if not set.
*/
const targetWorld = env.WORKFLOW_TARGET_WORLD || "local";
let world;
if (targetWorld === "vercel") {
	const token = process.env.WORKFLOW_VERCEL_AUTH_TOKEN;
	world = createVercelWorld({
		token: token?.trim() || void 0,
		baseUrl: process.env.WORKFLOW_VERCEL_BASE_URL || void 0,
		projectConfig: {
			projectId: process.env.VERCEL_PROJECT_ID,
			teamId: process.env.VERCEL_TEAM_ID,
			environment: process.env.VERCEL_ENV
		}
	});
} else if (targetWorld === "@workflow/world-postgres") world = createWorld({
	connectionString: env.WORKFLOW_POSTGRES_URL || "postgres://world:world@localhost:5432/world",
	jobPrefix: env.WORKFLOW_POSTGRES_JOB_PREFIX,
	queueConcurrency: Number(env.WORKFLOW_POSTGRES_WORKER_CONCURRENCY) || 10
});
else world = createLocalWorld();

//#endregion
export { world };