/*
 * Copyright 2026, Jaime Terrats.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { Hono } from 'hono';
import { ALL_PROFILES } from '../../profiles/index.js';
import { buildWorkspaceConfig, writeWorkspaceConfig } from '../../services/workspace-config.js';
import { setupLocalState } from '../../services/local-state.js';
import { FileWriter } from '../../services/file-writer.js';
export function initRoute(cwd) {
    const app = new Hono();
    app.post('/', async (c) => {
        const body = await c.req.json();
        const profiles = ALL_PROFILES.filter((p) => body.profiles.includes(p.id));
        if (profiles.length === 0) {
            return c.json({ error: 'At least one profile must be selected' }, 400);
        }
        const config = buildWorkspaceConfig({
            mode: body.mode,
            profiles,
            tools: body.tools,
        });
        if (!body.orchestration) {
            config.orchestration.enabled = false;
        }
        const writeResult = writeWorkspaceConfig(cwd, config, { force: true });
        const noop = () => {
            /* intentional no-op */
        };
        const writer = new FileWriter({ force: true, log: noop, warn: noop });
        setupLocalState(cwd, writer);
        const generatedFiles = [writeResult.path];
        return c.json({
            configFile: writeResult.path,
            generatedFiles,
            config,
        });
    });
    return app;
}
//# sourceMappingURL=init.js.map