// Planu — Documentation Builder Helpers
// Pure utility functions for building markdown sections
export function buildReadmeIntro(knowledge) {
    const parts = [];
    parts.push(`A ${knowledge.language} project${knowledge.framework ? ` built with ${knowledge.framework}` : ''}.`);
    if (knowledge.database !== 'unknown') {
        parts.push(`Uses ${knowledge.database} for data storage.`);
    }
    parts.push(`Architecture: ${knowledge.architecture.primary}.`);
    return parts.join(' ');
}
export function buildTechStackSection(knowledge) {
    const items = [];
    items.push(`- **Language:** ${knowledge.language}`);
    if (knowledge.framework) {
        items.push(`- **Framework:** ${knowledge.framework}`);
    }
    if (knowledge.database !== 'unknown') {
        items.push(`- **Database:** ${knowledge.database}`);
    }
    if (knowledge.packageManager) {
        items.push(`- **Package Manager:** ${knowledge.packageManager}`);
    }
    items.push(`- **Architecture:** ${knowledge.architecture.primary}`);
    return items.join('\n');
}
export function buildGettingStartedSection(knowledge) {
    const steps = [];
    steps.push('```bash');
    steps.push('# Clone the repository');
    steps.push('git clone <repository-url>');
    steps.push('cd <project-directory>');
    steps.push('');
    if (knowledge.packageManager) {
        const installCmd = getInstallCommand(knowledge.packageManager);
        steps.push('# Install dependencies');
        steps.push(installCmd);
        steps.push('');
    }
    steps.push('# Set up environment');
    steps.push('cp .env.example .env');
    steps.push('');
    if (knowledge.buildCommand) {
        steps.push('# Build');
        steps.push(knowledge.buildCommand);
        steps.push('');
    }
    if (knowledge.testCommand) {
        steps.push('# Run tests');
        steps.push(knowledge.testCommand);
    }
    steps.push('```');
    return steps.join('\n');
}
export function buildProjectStructureSection(knowledge) {
    const lines = ['```'];
    for (const layer of knowledge.architecture.layers) {
        for (const dir of layer.directories) {
            lines.push(`${dir}/    # ${layer.responsibility}`);
        }
    }
    lines.push('```');
    return lines.join('\n');
}
export function buildDevelopmentSection(knowledge) {
    const parts = [];
    if (knowledge.buildCommand) {
        parts.push(`**Build:** \`${knowledge.buildCommand}\``);
    }
    if (knowledge.testCommand) {
        parts.push(`**Test:** \`${knowledge.testCommand}\``);
    }
    parts.push('');
    parts.push('### Workflow');
    parts.push('');
    parts.push('This project follows Spec Driven Development (SDD). See the specs directory for current specifications.');
    return parts.join('\n');
}
export function buildPrerequisitesSection(knowledge) {
    const prerequisites = [];
    const langVersions = {
        typescript: 'Node.js 18+ and npm/pnpm/yarn',
        javascript: 'Node.js 18+ and npm/pnpm/yarn',
        python: 'Python 3.10+',
        go: 'Go 1.21+',
        rust: 'Rust 1.70+ (via rustup)',
        java: 'Java 17+ and Maven/Gradle',
        kotlin: 'Kotlin 1.9+ and Gradle',
        php: 'PHP 8.2+ and Composer',
        ruby: 'Ruby 3.2+ and Bundler',
        swift: 'Xcode 15+ and Swift 5.9+',
        dart: 'Dart 3.0+ and Flutter SDK',
        csharp: '.NET 8+ SDK',
    };
    prerequisites.push(`- ${langVersions[knowledge.language] ?? `${knowledge.language} (latest stable)`}`);
    if (knowledge.database !== 'unknown') {
        prerequisites.push(`- ${knowledge.database} (local or cloud)`);
    }
    prerequisites.push('- Git');
    return prerequisites.join('\n');
}
export function buildInstallationSection(knowledge) {
    const steps = [];
    steps.push('```bash');
    steps.push('# Clone the repository');
    steps.push('git clone <repository-url>');
    steps.push('cd <project-directory>');
    if (knowledge.packageManager) {
        steps.push('');
        steps.push('# Install dependencies');
        steps.push(getInstallCommand(knowledge.packageManager));
    }
    steps.push('```');
    return steps.join('\n');
}
export function buildEnvVarsSection(knowledge) {
    const envVars = knowledge.envSetup.variables;
    if (envVars.length === 0) {
        return 'Copy the example environment file and fill in the values:\n\n```bash\ncp .env.example .env\n```';
    }
    const lines = [];
    lines.push('Copy the example environment file:\n\n```bash\ncp .env.example .env\n```\n');
    lines.push('Required variables:\n');
    lines.push('| Variable | Service | Required | Sensitive |');
    lines.push('|----------|---------|----------|-----------|');
    for (const v of envVars) {
        lines.push(`| \`${v.name}\` | ${v.service} | ${v.required ? 'Yes' : 'No'} | ${v.sensitive ? 'Yes' : 'No'} |`);
    }
    return lines.join('\n');
}
export function buildDatabaseSetupSection(knowledge) {
    if (knowledge.database === 'unknown') {
        return 'No database configured for this project.';
    }
    return [
        `This project uses **${knowledge.database}**.`,
        '',
        '1. Ensure the database service is running.',
        '2. Set the connection string in your `.env` file.',
        '3. Run migrations (if applicable).',
    ].join('\n');
}
export function buildRunningSection(knowledge) {
    const lines = ['```bash'];
    if (knowledge.buildCommand) {
        lines.push(`# Build the project`);
        lines.push(knowledge.buildCommand);
        lines.push('');
    }
    lines.push('# Start the development server');
    lines.push('# (replace with your actual start command)');
    lines.push(knowledge.buildCommand?.replace('build', 'dev') ?? 'npm run dev');
    lines.push('```');
    return lines.join('\n');
}
export function buildVerifySection(knowledge) {
    const checks = [];
    if (knowledge.buildCommand) {
        checks.push(`- [ ] Build succeeds: \`${knowledge.buildCommand}\``);
    }
    if (knowledge.testCommand) {
        checks.push(`- [ ] Tests pass: \`${knowledge.testCommand}\``);
    }
    checks.push('- [ ] Application starts without errors');
    checks.push('- [ ] Can access the application in browser/CLI');
    return checks.join('\n');
}
export function buildDeploymentInstructions(unit, _knowledge) {
    const instructions = {
        docker: '1. Build the Docker image: `docker build -t app .`\n2. Run: `docker run -p 3000:3000 app`',
        'docker-compose': '1. Run: `docker-compose up -d`\n2. Check logs: `docker-compose logs -f`',
        vercel: '1. Install Vercel CLI: `npm i -g vercel`\n2. Deploy: `vercel`',
        railway: '1. Install Railway CLI\n2. Deploy: `railway up`',
        netlify: '1. Push to the connected Git branch\n2. Netlify will auto-deploy',
        'fly.io': '1. Install flyctl\n2. Deploy: `fly deploy`',
        manual: 'Manual deployment — document your specific deployment steps here.',
    };
    return instructions[unit] ?? `Deployment to ${unit} — document your steps here.`;
}
export function buildSecurityEnvSection(knowledge) {
    const security = knowledge.envSetup.security;
    const checks = [];
    checks.push(`- .env in .gitignore: ${security.gitignoreHasEnv ? 'Yes' : '**NO — FIX IMMEDIATELY**'}`);
    checks.push(`- No .env committed to git: ${security.noEnvInGit ? 'Yes' : '**NO — REMOVE FROM GIT**'}`);
    checks.push(`- No secrets in code: ${security.noSecretsInCode ? 'Yes' : 'Needs review'}`);
    checks.push(`- Uses secret manager: ${security.usesSecretManager ? 'Yes' : 'Not configured'}`);
    if (security.issues.length > 0) {
        checks.push('');
        checks.push('### Issues');
        for (const issue of security.issues) {
            checks.push(`- [${issue.severity.toUpperCase()}] ${issue.issue}: ${issue.fix}`);
        }
    }
    return checks.join('\n');
}
export function getInstallCommand(packageManager) {
    const commands = {
        npm: 'npm install',
        pnpm: 'pnpm install',
        yarn: 'yarn',
        bun: 'bun install',
        pip: 'pip install -r requirements.txt',
        poetry: 'poetry install',
        uv: 'uv sync',
        pipenv: 'pipenv install',
        cargo: 'cargo build',
        'go-mod': 'go mod download',
        composer: 'composer install',
        bundler: 'bundle install',
        pub: 'flutter pub get',
        mix: 'mix deps.get',
        spm: 'swift package resolve',
    };
    return commands[packageManager] ?? `${packageManager} install`;
}
export function buildMobileInstallGuide(platform) {
    if (platform === 'ios') {
        return [
            '### TestFlight (Beta / Internal)',
            '1. Open the **TestFlight** app on your iPhone or iPad.',
            '2. Accept the invitation email from the development team.',
            '3. Tap **Install** next to the app build.',
            '4. The app will appear on your home screen.',
            '',
            '### App Store (Production)',
            '1. Open the **App Store** on your device.',
            '2. Search for the app by name or use the direct link provided by the team.',
            '3. Tap **Get** → authenticate with Face ID / Touch ID.',
            '4. Wait for the download to complete.',
            '',
            '> **Requirements:** iOS 16+. Compatible with iPhone and iPad.',
        ].join('\n');
    }
    if (platform === 'android') {
        return [
            '### Firebase App Distribution (Beta / Internal)',
            '1. Open the invitation email on your Android device.',
            '2. Tap **Download latest build**.',
            '3. If prompted, enable **Install from unknown sources** for your browser.',
            '4. Open the downloaded APK and tap **Install**.',
            '',
            '### Google Play Store (Production)',
            '1. Open **Google Play Store** on your device.',
            '2. Search for the app or use the direct Play Store link.',
            '3. Tap **Install** and wait for the download.',
            '',
            '> **Requirements:** Android 8.0+ (API 26). ARM64 or x86_64 device.',
        ].join('\n');
    }
    return [
        '### iOS — See TestFlight section above.',
        '### Android — See Firebase App Distribution section above.',
    ].join('\n');
}
//# sourceMappingURL=builders.js.map