// cli/commands/init.ts — planu init [path] (SPEC-124)
import { parseArgs } from 'node:util';
import { resolve } from 'node:path';
import { handleInitProject } from '../../tools/init-project.js';
import { formatToolResult } from '../formatter.js';
import { green, red } from '../colors.js';
export const initCommand = {
    name: 'init',
    description: 'Initialize a project for Planu',
    usage: 'planu init [path] [--locale en] [--rate 100]',
    async run(args, flags) {
        const { values, positionals } = parseArgs({
            args,
            options: {
                locale: { type: 'string', short: 'l' },
                rate: { type: 'string', short: 'r' },
                level: { type: 'string' },
                profile: { type: 'string' },
            },
            strict: false,
            allowPositionals: true,
        });
        const projectPath = resolve(positionals[0] ?? process.cwd());
        const locale = values.locale ?? undefined;
        const hourlyRate = values.rate ? Number(values.rate) : undefined;
        const experienceLevel = values.level ?? undefined;
        const userProfile = values.profile ?? undefined;
        const result = await handleInitProject({
            projectPath,
            locale: locale,
            hourlyRate,
            experienceLevel: experienceLevel,
            userProfile: userProfile,
        });
        if (result.isError) {
            process.stderr.write(`${red(formatToolResult(result, flags))}\n`);
            process.exitCode = 1;
            return;
        }
        const output = formatToolResult(result, flags);
        if (flags?.quiet) {
            if (output) {
                process.stdout.write(output + '\n');
            }
        }
        else {
            process.stdout.write(`${green('Project initialized!')} ${output}\n`);
        }
    },
};
//# sourceMappingURL=init.js.map