//#region src/presentation/config/CodemationAuthoring.types.ts
var CodemationAuthoringConfigFactory = class {
	static createApp(options) {
		const appDefinition = this.createAppDefinition(options);
		const credentialTypes = [...options.credentialTypes ?? [], ...options.credentials ?? []];
		const register = this.composeAppRegister(options.register, options.nodes, options.collections);
		const { workflows, plugins, runtime, log, mcpServers, codemationVersion } = options;
		return {
			workflows,
			workflowDiscovery: this.mergeWorkflowDiscovery(options.workflowDiscovery, options.workflowsDir),
			plugins,
			runtime,
			log,
			mcpServers,
			codemationVersion,
			app: appDefinition,
			credentialTypes,
			register
		};
	}
	static createPlugin(options) {
		return {
			pluginPackageId: options.pluginPackageId,
			sandbox: options.sandbox,
			mcpServers: options.mcpServers,
			async register(context) {
				for (const nodeDefinition of options.nodes ?? []) nodeDefinition.register(context);
				for (const collection of options.collections ?? []) collection.register(context);
				for (const credential of options.credentials ?? []) context.registerCredentialType(credential);
				await options.register?.(context);
			}
		};
	}
	static createAppDefinition(options) {
		const scheduler = this.createSchedulerConfig(options.execution);
		const database = this.createDatabaseConfig(options.database);
		const whitelabel = this.createWhitelabel(options.name, options.whitelabel);
		if (!options.auth && !database && !scheduler && !whitelabel) return;
		return {
			auth: options.auth,
			database,
			scheduler,
			whitelabel
		};
	}
	static createDatabaseConfig(database) {
		if (!database) return;
		if (database.kind === "sqlite") return {
			kind: "sqlite",
			sqliteFilePath: database.filePath
		};
		if (database.url !== void 0 && database.urlEnv !== void 0) throw new Error("defineCodemationApp: database.url and database.urlEnv are mutually exclusive — provide one or the other.");
		return {
			kind: "postgresql",
			url: database.urlEnv !== void 0 ? process.env[database.urlEnv] : database.url
		};
	}
	static createSchedulerConfig(execution) {
		if (!execution) return;
		if (execution.mode !== void 0 && execution.modeEnv !== void 0) throw new Error("defineCodemationApp: execution.mode and execution.modeEnv are mutually exclusive — provide one or the other.");
		if (execution.redisUrl !== void 0 && execution.redisUrlEnv !== void 0) throw new Error("defineCodemationApp: execution.redisUrl and execution.redisUrlEnv are mutually exclusive — provide one or the other.");
		const rawMode = execution.modeEnv !== void 0 ? process.env[execution.modeEnv] : execution.mode;
		const mode = rawMode === "inline" || rawMode === "queue" ? rawMode : void 0;
		const redisUrl = execution.redisUrlEnv !== void 0 ? process.env[execution.redisUrlEnv] : execution.redisUrl;
		return {
			kind: mode,
			queuePrefix: execution.queuePrefix,
			workerQueues: execution.workerQueues,
			redisUrl
		};
	}
	static mergeWorkflowDiscovery(existing, workflowsDir) {
		if (!workflowsDir) return existing;
		return { directories: [...existing?.directories ?? [], workflowsDir] };
	}
	static createWhitelabel(name, whitelabel) {
		if (!name && !whitelabel) return;
		return {
			productName: name ?? whitelabel?.productName,
			logoPath: whitelabel?.logoPath
		};
	}
	static composeAppRegister(register, nodes, collections) {
		if (!register && (!nodes || nodes.length === 0) && (!collections || collections.length === 0)) return;
		return (context) => {
			for (const nodeDefinition of nodes ?? []) nodeDefinition.register(context);
			for (const collection of collections ?? []) collection.register(context);
			register?.(context);
		};
	}
};
function defineCodemationApp(options) {
	return CodemationAuthoringConfigFactory.createApp(options);
}
function definePlugin(options) {
	return CodemationAuthoringConfigFactory.createPlugin(options);
}

//#endregion
export { definePlugin as n, defineCodemationApp as t };
//# sourceMappingURL=CodemationAuthoring.types-BteaR3Dc.js.map