import { ti } from '../../i18n/index.js';
import { createBasicPhaseEvent } from '../../engine/phase-tracker.js';
import { buildWebConsultHints } from './helpers.js';
export function buildInitProjectResult(input) {
    const { knowledge, isUpdate } = input;
    const isEmpty = knowledge.language === 'unknown' && knowledge.framework === null && knowledge.apps.length <= 1;
    const webConsultHints = buildWebConsultHints(knowledge.language, knowledge.framework, knowledge.database);
    const detectedPlatforms = Object.keys(knowledge.conventions).filter((k) => k.endsWith('-rules') || k === 'ai-rules');
    const platformHint = detectedPlatforms.length === 0
        ? 'No AI coding platform detected. Which platform are you using? ' +
            '(Claude Code, Cursor, Windsurf, Copilot, Cline, Codex, Antigravity, ' +
            'Gemini, Amazon Q, Devin, Aider, Continue, JetBrains Junie, etc.)'
        : null;
    const result = {
        projectId: input.projectId,
        projectPath: input.projectPath,
        isUpdate: input.isUpdate,
        isEmpty,
        language: knowledge.language,
        languageVersion: knowledge.languageVersion,
        framework: knowledge.framework,
        frameworkVersion: knowledge.frameworkVersion,
        packageManager: knowledge.packageManager,
        database: knowledge.database,
        orm: knowledge.orm,
        architecture: knowledge.architecture.primary,
        secondaryPatterns: knowledge.architecture.secondary,
        apps: knowledge.apps.map((a) => ({
            name: a.name,
            type: a.type,
            language: a.language,
            framework: a.framework,
            orm: a.orm,
            architecture: a.architecture,
        })),
        monorepo: knowledge.monorepo,
        layers: knowledge.layers,
        stack: knowledge.stack,
        specLocation: knowledge.specLocation,
        locale: knowledge.locale,
        experienceLevel: knowledge.experienceLevel,
        userProfile: knowledge.userProfile ?? null,
        environments: knowledge.environments,
        linting: {
            maturityScore: knowledge.linting.maturityScore,
            configuredLinters: knowledge.linting.detectedLinters
                .filter((l) => l.status === 'configured')
                .map((l) => l.tool),
            conflicts: knowledge.linting.rulesConflicts.length,
        },
        conventions: knowledge.conventions,
        externalServices: knowledge.externalServices,
        tooling: knowledge.tooling,
        apiContracts: knowledge.apiContracts.map((c) => c.type),
        deploymentUnits: knowledge.architecture.deploymentUnits,
        availableMcps: knowledge.availableMcps.length,
        qualityProfile: {
            strictness: knowledge.qualityProfile.strictness,
            customRulesFromClaudeMd: input.claudeMdRules.length,
        },
        webConsultHints,
        detectedPlatforms,
        platformHint,
        privacyConfig: {
            framework: input.privacyConfig.framework,
            defaultRetentionDays: input.privacyConfig.defaultRetentionDays,
            auditRetentionDays: input.privacyConfig.auditRetentionDays,
            dataProcessorsFound: input.privacyConfig.dataProcessors.length,
            dataProcessors: input.privacyConfig.dataProcessors.map((dp) => ({
                destination: dp.destination,
                type: dp.destinationType,
                requiresDPAReview: dp.requiresDPAReview,
            })),
        },
        completeness: {
            score: input.completeness.completenessScore,
            hasReadme: input.completeness.hasReadme,
            hasGitignore: input.completeness.hasGitignore,
            hasEnvExample: input.completeness.hasEnvExample,
            hasLicense: input.completeness.hasLicense,
            hasLinting: input.completeness.hasLinting,
            hasFormatting: input.completeness.hasFormatting,
            hasTesting: input.completeness.hasTesting,
            hasCiCd: input.completeness.hasCiCd,
            hasErrorTracking: input.completeness.hasErrorTracking,
            hasTypeChecking: input.completeness.hasTypeChecking,
            hasSecurityScanning: input.completeness.hasSecurityScanning,
            hasDocumentation: input.completeness.hasDocumentation,
        },
        modernArchitecturePatterns: input.modernPatterns.map((p) => ({
            name: p.name,
            confidence: p.confidence,
            indicators: p.indicators,
        })),
        dddDetected: input.dddConfig.detected,
        dddBoundedContexts: input.dddConfig.boundedContexts,
        agileProcess: input.agileDetection.process,
        agileConfidence: input.agileDetection.confidence,
        agileConfig: input.agileDetection.agileConfig,
        agileIndicators: input.agileDetection.indicators,
        orchestratorInfo: {
            orchestrator: input.orchestratorInfo.orchestrator,
            ...(input.orchestratorInfo.note ? { note: input.orchestratorInfo.note } : {}),
        },
        composeMultiplatform: input.composeMultiplatform.detected
            ? { crossPlatformEngine: input.composeMultiplatform.crossPlatformEngine }
            : null,
        message: isEmpty
            ? ti('project.emptyProject', {})
            : isUpdate
                ? ti('project.alreadyExists', {})
                : ti('project.initialized', {
                    language: knowledge.language,
                    framework: knowledge.framework ?? 'none',
                }),
        contextRequest: input.contextRequestPrompt
            ? {
                prompt: input.contextRequestPrompt,
                missingAreas: input.missingAreas,
                message: 'Please share the above documents so I can learn your project context.',
            }
            : null,
        envExample: input.envExampleGenerated !== null
            ? { generated: true, variablesCount: input.envExampleGenerated }
            : { generated: false, variablesCount: knowledge.envSetup.variables.length },
        beginnerEnvGuide: input.beginnerEnvGuide,
        recommendedSkills: input.recommendedSkills.map((s) => ({
            name: s.name,
            description: s.description,
            installCommand: s.installCommand,
            justification: s.justification,
        })),
        planuConfig: input.planuConfigGenerated
            ? { generated: true, path: input.planuConfigPath }
            : { generated: false, path: input.planuConfigPath, note: 'Already exists' },
        generatedRules: {
            platform: input.platform,
            filePath: input.generatedRules.rulesFile.path,
            written: input.rulesWritten,
            additionalFilesWritten: input.additionalFilesWritten,
            skillsIncluded: input.recommendedSkills.length,
        },
        specMigration: input.migrationResult,
        gitAutomation: {
            hooksInstalled: input.hooksInstalled,
            gitFlowType: input.gitFlowType,
            gitignoreUpdated: input.gitignoreUpdated,
            constitutionInitialized: input.constitutionInitialized,
        },
    };
    return {
        phaseEvent: createBasicPhaseEvent('init_project', 'completed', 100, 'initializing'),
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
    };
}
//# sourceMappingURL=result-builder.js.map