'use server';
import { resolve } from '../../lib/server-container.js';
/**
 * Thin server-action wrapper around CreateApplicationUseCase.
 *
 * All orchestration (slug allocation, project scaffold, app persistence,
 * prompt building, first-message dispatch) lives inside the use case so
 * every presentation layer (Web / CLI / TUI) gets identical behavior
 * from a single call.
 */
export async function createApplication(input) {
    if (!input.description?.trim()) {
        return { error: 'Description is required' };
    }
    try {
        const useCase = resolve('CreateApplicationUseCase');
        const result = await useCase.execute({
            description: input.description.trim(),
            agentType: input.agentType,
            modelOverride: input.modelOverride,
            initialPrompt: input.initialPrompt,
        });
        return { application: result.application, repositoryPath: result.repositoryPath };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to create application';
        return { error: message };
    }
}
