"use strict";
/**
 * Setup Guide Documentation Template
 * Generates step-by-step setup instructions based on technology stack
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetupGuideTemplate = void 0;
const base_template_1 = require("./base-template");
class SetupGuideTemplate extends base_template_1.DocumentationTemplate {
    canHandle(intent) {
        return intent.type === 'setup_guide';
    }
    generate(context) {
        const { intent, workflow } = context;
        let content = `# ${workflow.workflow.name} - Setup Guide\n\n`;
        content += `${workflow.workflow.description}\n\n`;
        // Prerequisites
        content += this.generatePrerequisites(context);
        // Installation steps
        content += this.generateInstallation(context);
        // Configuration
        content += this.generateConfiguration(context);
        // Running the application
        content += this.generateRunning(context);
        // Verification
        content += this.generateVerification(context);
        // Optional: Examples if requested
        if (intent.includeExamples) {
            content += this.generateExamples(context);
        }
        content += this.generateFooter(context);
        return content;
    }
    generatePrerequisites(context) {
        const { extendedWorkflow } = context;
        let content = `## Prerequisites\n\n`;
        content += `Before you begin, ensure you have the following installed:\n\n`;
        // Node.js (required for TypeScript-based stacks)
        if (extendedWorkflow?.technology?.frontend?.language === 'typescript' ||
            extendedWorkflow?.technology?.backend?.language === 'typescript') {
            content += `- **Node.js** (v18 or higher) - [Download](https://nodejs.org/)\n`;
            content += `- **npm** or **yarn** package manager\n`;
        }
        // Database
        if (extendedWorkflow?.technology?.database?.type) {
            const dbType = extendedWorkflow.technology.database.type;
            const dbVersion = extendedWorkflow.technology.database.version;
            if (dbType === 'postgresql') {
                content += `- **PostgreSQL** ${dbVersion ? `(v${dbVersion})` : ''} - [Download](https://www.postgresql.org/download/) or use Docker\n`;
            }
            else if (dbType === 'mysql') {
                content += `- **MySQL** ${dbVersion ? `(v${dbVersion})` : ''} - [Download](https://dev.mysql.com/downloads/) or use Docker\n`;
            }
            else if (dbType === 'mongodb') {
                content += `- **MongoDB** ${dbVersion ? `(v${dbVersion})` : ''} - [Download](https://www.mongodb.com/try/download/community) or use Docker\n`;
            }
        }
        // Git
        content += `- **Git** - [Download](https://git-scm.com/downloads)\n`;
        // Optional: Docker
        content += `\n**Optional (Recommended):**\n`;
        content += `- **Docker** and **Docker Compose** - For running services locally\n\n`;
        return content;
    }
    generateInstallation(context) {
        const { workflow, extendedWorkflow } = context;
        let content = `## Installation\n\n`;
        content += `### 1. Clone the repository\n\n`;
        content += '```bash\n';
        content += `git clone <repository-url>\n`;
        content += `cd ${workflow.workflow.id}\n`;
        content += '```\n\n';
        // Install dependencies for each component
        const hasFrontend = extendedWorkflow?.technology?.frontend;
        const hasBackend = extendedWorkflow?.technology?.backend;
        if (hasBackend) {
            content += `### 2. Install backend dependencies\n\n`;
            content += '```bash\n';
            content += `cd backend\n`;
            content += `npm install\n`;
            content += '```\n\n';
        }
        if (hasFrontend) {
            content += `### ${hasBackend ? '3' : '2'}. Install frontend dependencies\n\n`;
            content += '```bash\n';
            content += `cd frontend\n`;
            content += `npm install\n`;
            content += '```\n\n';
        }
        return content;
    }
    generateConfiguration(context) {
        const { extendedWorkflow } = context;
        let content = `## Configuration\n\n`;
        const hasAuth = extendedWorkflow?.auth?.enabled;
        const hasDatabase = extendedWorkflow?.technology?.database;
        content += `### Environment Variables\n\n`;
        content += `Create \`.env\` files with the required configuration:\n\n`;
        // Backend environment variables
        if (extendedWorkflow?.technology?.backend) {
            content += `#### Backend (\`backend/.env\`)\n\n`;
            content += '```bash\n';
            content += `# Server Configuration\n`;
            content += `PORT=3001\n`;
            content += `NODE_ENV=development\n\n`;
            if (hasDatabase) {
                const dbType = extendedWorkflow.technology.database.type;
                content += `# Database\n`;
                if (dbType === 'postgresql') {
                    content += `DATABASE_URL=postgresql://user:password@localhost:5432/dbname\n\n`;
                }
                else if (dbType === 'mysql') {
                    content += `DATABASE_URL=mysql://user:password@localhost:3306/dbname\n\n`;
                }
                else if (dbType === 'mongodb') {
                    content += `DATABASE_URL=mongodb://localhost:27017/dbname\n\n`;
                }
            }
            if (hasAuth) {
                const provider = extendedWorkflow.auth.provider;
                content += `# Authentication\n`;
                if (provider === 'clerk') {
                    content += `CLERK_SECRET_KEY=sk_test_your_secret_key_here\n`;
                    content += `CLERK_PUBLISHABLE_KEY=pk_test_your_publishable_key_here\n\n`;
                }
                else if (provider === 'auth0') {
                    content += `AUTH0_DOMAIN=your-domain.auth0.com\n`;
                    content += `AUTH0_AUDIENCE=your-api-identifier\n\n`;
                }
            }
            content += `# CORS\n`;
            content += `FRONTEND_URL=http://localhost:5173\n`;
            content += '```\n\n';
        }
        // Frontend environment variables
        if (extendedWorkflow?.technology?.frontend) {
            content += `#### Frontend (\`frontend/.env\`)\n\n`;
            content += '```bash\n';
            if (hasAuth) {
                const provider = extendedWorkflow.auth.provider;
                if (provider === 'clerk') {
                    content += `# Clerk Configuration\n`;
                    content += `VITE_CLERK_PUBLISHABLE_KEY=pk_test_your_publishable_key_here\n\n`;
                }
                else if (provider === 'auth0') {
                    content += `# Auth0 Configuration\n`;
                    content += `VITE_AUTH0_DOMAIN=your-domain.auth0.com\n`;
                    content += `VITE_AUTH0_CLIENT_ID=your_client_id\n`;
                    content += `VITE_AUTH0_AUDIENCE=your-api-identifier\n\n`;
                }
            }
            content += `# API Configuration\n`;
            content += `VITE_API_URL=http://localhost:3001\n`;
            content += '```\n\n';
        }
        // Auth provider setup instructions
        if (hasAuth) {
            const provider = extendedWorkflow.auth.provider;
            content += `### ${this.getTechnologyName(provider || '')} Setup\n\n`;
            if (provider === 'clerk') {
                content += `1. Create a free account at [clerk.com](https://clerk.com)\n`;
                content += `2. Create a new application\n`;
                content += `3. Copy your API keys from the Clerk dashboard\n`;
                content += `4. Add the keys to your \`.env\` files (above)\n\n`;
            }
            else if (provider === 'auth0') {
                content += `1. Create a free account at [auth0.com](https://auth0.com)\n`;
                content += `2. Create a new API\n`;
                content += `3. Create a new Application (Single Page Application)\n`;
                content += `4. Copy your domain, client ID, and audience\n`;
                content += `5. Add the credentials to your \`.env\` files (above)\n\n`;
            }
        }
        // Database setup
        if (hasDatabase) {
            content += `### Database Setup\n\n`;
            content += `#### Option 1: Using Docker (Recommended)\n\n`;
            content += '```bash\n';
            content += `docker compose up -d\n`;
            content += '```\n\n';
            content += `#### Option 2: Local Installation\n\n`;
            const dbType = extendedWorkflow.technology.database.type;
            if (dbType === 'postgresql') {
                content += `Install PostgreSQL and create a database:\n`;
                content += '```bash\n';
                content += `createdb your_database_name\n`;
                content += '```\n\n';
            }
            content += `#### Run Migrations\n\n`;
            content += '```bash\n';
            content += `cd backend\n`;
            content += `npm run prisma:migrate\n`;
            content += '```\n\n';
        }
        return content;
    }
    generateRunning(context) {
        const { extendedWorkflow } = context;
        let content = `## Running the Application\n\n`;
        const hasBackend = extendedWorkflow?.technology?.backend;
        const hasFrontend = extendedWorkflow?.technology?.frontend;
        if (hasBackend && hasFrontend) {
            content += `You'll need two terminal windows:\n\n`;
            content += `### Terminal 1: Backend\n\n`;
            content += '```bash\n';
            content += `cd backend\n`;
            content += `npm run dev\n`;
            content += '```\n\n';
            content += `Backend will start on [http://localhost:3001](http://localhost:3001)\n\n`;
            content += `### Terminal 2: Frontend\n\n`;
            content += '```bash\n';
            content += `cd frontend\n`;
            content += `npm run dev\n`;
            content += '```\n\n';
            content += `Frontend will start on [http://localhost:5173](http://localhost:5173)\n\n`;
        }
        else if (hasBackend) {
            content += '```bash\n';
            content += `cd backend\n`;
            content += `npm run dev\n`;
            content += '```\n\n';
        }
        else if (hasFrontend) {
            content += '```bash\n';
            content += `cd frontend\n`;
            content += `npm run dev\n`;
            content += '```\n\n';
        }
        return content;
    }
    generateVerification(context) {
        const { extendedWorkflow } = context;
        let content = `## Verification\n\n`;
        content += `To verify everything is working:\n\n`;
        const hasFrontend = extendedWorkflow?.technology?.frontend;
        const hasBackend = extendedWorkflow?.technology?.backend;
        if (hasFrontend) {
            content += `1. Open [http://localhost:5173](http://localhost:5173) in your browser\n`;
        }
        if (hasBackend) {
            content += `2. Check backend health: [http://localhost:3001/health](http://localhost:3001/health)\n`;
        }
        if (extendedWorkflow?.auth?.enabled) {
            content += `3. Try signing up or logging in\n`;
        }
        content += `\nIf you encounter any issues, see the [Troubleshooting Guide](troubleshooting.md).\n\n`;
        return content;
    }
    generateExamples(context) {
        const { extendedWorkflow } = context;
        let content = `## Example Usage\n\n`;
        if (extendedWorkflow?.auth?.enabled) {
            content += `### Making Authenticated API Requests\n\n`;
            content += '```typescript\n';
            content += `// Frontend example\n`;
            content += `const response = await fetch('http://localhost:3001/api/users', {\n`;
            content += `  credentials: 'include', // Important for auth\n`;
            content += `  headers: {\n`;
            content += `    'Content-Type': 'application/json'\n`;
            content += `  }\n`;
            content += `});\n\n`;
            content += `const users = await response.json();\n`;
            content += '```\n\n';
        }
        return content;
    }
}
exports.SetupGuideTemplate = SetupGuideTemplate;
//# sourceMappingURL=setup-guide-template.js.map