"use strict";
/**
 * README Generator
 * Generates comprehensive README.md with setup instructions
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReadmeGenerator = void 0;
const path = __importStar(require("path"));
class ReadmeGenerator {
    id = 'readme';
    name = 'README Generator';
    description = 'Generates README.md with setup instructions';
    generate(context) {
        const { workflow, outputDirectory, extendedWorkflow } = context;
        const files = [];
        // Generate root README.md
        files.push({
            path: path.join(outputDirectory, 'README.md'),
            content: this.generateRootReadme(workflow, extendedWorkflow),
            overwrite: false, // Don't overwrite if user has customized it
        });
        return { files };
    }
    generateRootReadme(workflow, extendedWorkflow) {
        const projectName = workflow.workflow.name || 'Project';
        const description = workflow.workflow.description || 'Generated with Bangstack';
        let content = `# ${projectName}\n\n`;
        content += `${description}\n\n`;
        // Add badges
        content += this.generateBadges(extendedWorkflow);
        // Table of contents
        content += `## Table of Contents\n\n`;
        content += `- [Overview](#overview)\n`;
        content += `- [Tech Stack](#tech-stack)\n`;
        content += `- [Getting Started](#getting-started)\n`;
        content += `  - [Prerequisites](#prerequisites)\n`;
        content += `  - [Installation](#installation)\n`;
        content += `  - [Configuration](#configuration)\n`;
        content += `  - [Running the Application](#running-the-application)\n`;
        if (extendedWorkflow?.auth?.enabled) {
            content += `- [Authentication Setup](#authentication-setup)\n`;
        }
        content += `- [Project Structure](#project-structure)\n`;
        content += `- [Development](#development)\n`;
        content += `- [Deployment](#deployment)\n`;
        content += `- [Generated with Bangstack](#generated-with-bangstack)\n\n`;
        // Overview
        content += `## Overview\n\n`;
        content += `This is a full-stack application generated with [Bangstack](https://bangstack.com). `;
        content += `It includes a complete development environment with all necessary tooling and configuration.\n\n`;
        // Tech Stack
        content += this.generateTechStack(workflow, extendedWorkflow);
        // Getting Started
        content += this.generateGettingStarted(workflow, extendedWorkflow);
        // Authentication Setup (if applicable)
        if (extendedWorkflow?.auth?.enabled) {
            content += this.generateAuthSetup(extendedWorkflow.auth);
        }
        // Project Structure
        content += this.generateProjectStructure(workflow, extendedWorkflow);
        // Development
        content += this.generateDevelopment(workflow, extendedWorkflow);
        // Deployment
        content += this.generateDeployment(workflow, extendedWorkflow);
        // Footer
        content += this.generateFooter(workflow);
        return content;
    }
    generateBadges(extendedWorkflow) {
        let badges = '';
        if (extendedWorkflow?.technology?.frontend?.framework === 'react') {
            badges += `![React](https://img.shields.io/badge/React-18-blue) `;
        }
        if (extendedWorkflow?.technology?.backend?.framework === 'express') {
            badges += `![Express](https://img.shields.io/badge/Express-4-green) `;
        }
        if (extendedWorkflow?.technology?.backend?.language === 'typescript') {
            badges += `![TypeScript](https://img.shields.io/badge/TypeScript-5-blue) `;
        }
        if (extendedWorkflow?.technology?.database?.type === 'postgresql') {
            badges += `![PostgreSQL](https://img.shields.io/badge/PostgreSQL-15-blue) `;
        }
        badges += `![Bangstack](https://img.shields.io/badge/Generated%20with-Bangstack-orange)\n\n`;
        return badges;
    }
    generateTechStack(workflow, extendedWorkflow) {
        let content = `## Tech Stack\n\n`;
        const tech = extendedWorkflow?.technology || {};
        if (tech.frontend) {
            content += `### Frontend\n\n`;
            content += `- **Framework**: ${this.capitalize(tech.frontend.framework)}\n`;
            if (tech.frontend.language) {
                content += `- **Language**: ${this.capitalize(tech.frontend.language)}\n`;
            }
            if (tech.frontend.styling) {
                content += `- **Styling**: ${this.capitalize(tech.frontend.styling)}\n`;
            }
            if (tech.frontend.state_management) {
                content += `- **State Management**: ${this.capitalize(tech.frontend.state_management)}\n`;
            }
            content += `- **Build Tool**: Vite\n\n`;
        }
        if (tech.backend) {
            content += `### Backend\n\n`;
            content += `- **Framework**: ${this.capitalize(tech.backend.framework)}\n`;
            content += `- **Language**: ${this.capitalize(tech.backend.language)}\n`;
            if (tech.backend.orm) {
                content += `- **ORM**: ${this.capitalize(tech.backend.orm)}\n`;
            }
            content += `\n`;
        }
        if (tech.database) {
            content += `### Database\n\n`;
            // Handle both string and object formats for database
            const dbType = typeof tech.database === 'string' ? tech.database : tech.database.type;
            const dbVersion = typeof tech.database === 'object' ? tech.database.version : undefined;
            content += `- **Type**: ${this.capitalize(dbType)}\n`;
            if (dbVersion) {
                content += `- **Version**: ${dbVersion}\n`;
            }
            content += `\n`;
        }
        if (extendedWorkflow?.auth?.enabled) {
            content += `### Authentication\n\n`;
            content += `- **Provider**: ${this.capitalize(extendedWorkflow.auth.provider)}\n`;
            if (extendedWorkflow.auth.strategies) {
                content += `- **Strategies**: ${extendedWorkflow.auth.strategies.join(', ')}\n`;
            }
            content += `\n`;
        }
        return content;
    }
    generateGettingStarted(workflow, extendedWorkflow) {
        const hasBackend = extendedWorkflow?.technology?.backend ||
            Object.values(workflow.stack).some((c) => c.type === 'backend');
        const hasFrontend = extendedWorkflow?.technology?.frontend ||
            Object.values(workflow.stack).some((c) => c.type === 'frontend');
        const hasDatabase = extendedWorkflow?.technology?.database;
        let content = `## Getting Started\n\n`;
        // Prerequisites
        content += `### Prerequisites\n\n`;
        content += `Before you begin, ensure you have the following installed:\n\n`;
        content += `- **Node.js** (v18 or higher) - [Download](https://nodejs.org/)\n`;
        content += `- **npm** or **yarn** - Package manager\n`;
        if (hasDatabase) {
            const dbType = extendedWorkflow?.technology?.database?.type || 'database';
            content += `- **${this.capitalize(dbType)}** - [Installation Guide](https://www.postgresql.org/download/)\n`;
        }
        content += `- **Docker** (optional, for containerized development) - [Download](https://www.docker.com/products/docker-desktop)\n\n`;
        // Installation
        content += `### Installation\n\n`;
        content += `1. **Clone the repository** (if using version control):\n\n`;
        content += `\`\`\`bash\n`;
        content += `git clone <your-repo-url>\n`;
        content += `cd ${workflow.workflow.id}\n`;
        content += `\`\`\`\n\n`;
        content += `2. **Install dependencies** for both backend and frontend:\n\n`;
        content += `\`\`\`bash\n`;
        if (hasBackend) {
            content += `# Install backend dependencies\n`;
            content += `cd backend\n`;
            content += `npm install\n\n`;
        }
        if (hasFrontend) {
            content += `# Install frontend dependencies\n`;
            content += `cd ../frontend\n`;
            content += `npm install\n`;
            content += `cd ..\n`;
        }
        content += `\`\`\`\n\n`;
        // Configuration
        content += `### Configuration\n\n`;
        if (hasBackend) {
            content += `1. **Set up environment variables** for the backend:\n\n`;
            content += `\`\`\`bash\n`;
            content += `cd backend\n`;
            content += `cp .env.example .env\n`;
            content += `\`\`\`\n\n`;
            content += `Edit \`.env\` and configure:\n\n`;
            if (hasDatabase) {
                content += `- Database connection URL\n`;
            }
            if (extendedWorkflow?.auth?.enabled) {
                if (extendedWorkflow.auth.provider === 'clerk') {
                    content += `- Clerk secret key\n`;
                }
                else if (extendedWorkflow.auth.provider === 'local' || extendedWorkflow.auth.provider === 'jwt') {
                    content += `- JWT secret\n`;
                }
            }
            content += `- Server port (default: 3000)\n\n`;
        }
        if (hasDatabase && extendedWorkflow?.technology?.backend?.orm === 'prisma') {
            content += `2. **Set up the database**:\n\n`;
            content += `\`\`\`bash\n`;
            content += `cd backend\n\n`;
            content += `# Generate Prisma client\n`;
            content += `npm run prisma:generate\n\n`;
            content += `# Run database migrations\n`;
            content += `npm run prisma:migrate\n`;
            content += `\`\`\`\n\n`;
        }
        // Running the Application
        content += `### Running the Application\n\n`;
        content += `You have several options for running the application:\n\n`;
        content += `#### Option 1: Using Docker Compose (Recommended)\n\n`;
        content += `The easiest way to run the entire stack:\n\n`;
        content += `\`\`\`bash\n`;
        content += `docker-compose up\n`;
        content += `\`\`\`\n\n`;
        if (hasBackend && hasFrontend) {
            content += `#### Option 2: Running Services Separately\n\n`;
            content += `**Terminal 1 - Backend:**\n\n`;
            content += `\`\`\`bash\n`;
            content += `cd backend\n`;
            content += `npm run dev\n`;
            content += `\`\`\`\n\n`;
            content += `**Terminal 2 - Frontend:**\n\n`;
            content += `\`\`\`bash\n`;
            content += `cd frontend\n`;
            content += `npm run dev\n`;
            content += `\`\`\`\n\n`;
        }
        content += `The application will be available at:\n\n`;
        if (hasFrontend) {
            content += `- **Frontend**: http://localhost:5173\n`;
        }
        if (hasBackend) {
            content += `- **Backend API**: http://localhost:3000\n`;
        }
        content += `\n`;
        return content;
    }
    generateAuthSetup(authConfig) {
        let content = `## Authentication Setup\n\n`;
        const provider = authConfig.provider;
        if (provider === 'clerk') {
            content += `This application uses **Clerk** for authentication. To set it up:\n\n`;
            content += `1. **Create a Clerk account**: Visit [clerk.com](https://clerk.com) and sign up\n\n`;
            content += `2. **Create a new application** in the Clerk dashboard\n\n`;
            content += `3. **Enable authentication strategies**: In your Clerk app settings, enable:\n`;
            if (authConfig.strategies) {
                authConfig.strategies.forEach((strategy) => {
                    content += `   - ${this.capitalize(strategy)}\n`;
                });
            }
            content += `\n4. **Get your API keys**:\n`;
            content += `   - Frontend: \`VITE_CLERK_PUBLISHABLE_KEY\`\n`;
            content += `   - Backend: \`CLERK_SECRET_KEY\`\n\n`;
            content += `5. **Update environment variables**:\n\n`;
            content += `**Backend** (\`backend/.env\`):\n`;
            content += `\`\`\`\n`;
            content += `CLERK_SECRET_KEY=sk_test_...\n`;
            content += `\`\`\`\n\n`;
            content += `**Frontend** (create \`frontend/.env\` if it doesn't exist):\n`;
            content += `\`\`\`\n`;
            content += `VITE_CLERK_PUBLISHABLE_KEY=pk_test_...\n`;
            content += `\`\`\`\n\n`;
            content += `6. **Restart your application** to apply the changes\n\n`;
        }
        else if (provider === 'local' || provider === 'jwt') {
            content += `This application uses **JWT-based authentication**.\n\n`;
            content += `The \`JWT_SECRET\` in your \`backend/.env\` file is used to sign and verify tokens. `;
            content += `Make sure to use a strong, random secret in production.\n\n`;
        }
        return content;
    }
    generateProjectStructure(workflow, extendedWorkflow) {
        const hasBackend = extendedWorkflow?.technology?.backend ||
            Object.values(workflow.stack).some((c) => c.type === 'backend');
        const hasFrontend = extendedWorkflow?.technology?.frontend ||
            Object.values(workflow.stack).some((c) => c.type === 'frontend');
        let content = `## Project Structure\n\n`;
        content += `\`\`\`\n`;
        content += `.\n`;
        if (hasBackend) {
            content += `├── backend/                 # Backend application\n`;
            content += `│   ├── src/                # Source code\n`;
            content += `│   │   ├── routes/         # API routes\n`;
            content += `│   │   ├── middleware/     # Express middleware\n`;
            if (extendedWorkflow?.technology?.backend?.orm === 'prisma') {
                content += `│   │   └── index.ts       # Application entry point\n`;
                content += `│   ├── prisma/            # Database schema and migrations\n`;
            }
            content += `│   ├── package.json       # Backend dependencies\n`;
            content += `│   └── .env.example       # Environment variables template\n`;
        }
        if (hasFrontend) {
            content += `├── frontend/               # Frontend application\n`;
            content += `│   ├── src/               # Source code\n`;
            content += `│   │   ├── pages/         # Page components\n`;
            content += `│   │   ├── components/    # Reusable components\n`;
            if (extendedWorkflow?.auth?.enabled) {
                content += `│   │   ├── hooks/         # Custom React hooks\n`;
            }
            content += `│   │   └── App.tsx        # Root component\n`;
            content += `│   ├── package.json       # Frontend dependencies\n`;
            content += `│   └── vite.config.ts     # Vite configuration\n`;
        }
        content += `├── docker-compose.yml      # Docker orchestration\n`;
        content += `├── ${workflow.workflow.id}.workflow.yaml  # Workflow definition\n`;
        content += `└── README.md               # This file\n`;
        content += `\`\`\`\n\n`;
        return content;
    }
    generateDevelopment(workflow, extendedWorkflow) {
        const hasBackend = extendedWorkflow?.technology?.backend ||
            Object.values(workflow.stack).some((c) => c.type === 'backend');
        const hasFrontend = extendedWorkflow?.technology?.frontend ||
            Object.values(workflow.stack).some((c) => c.type === 'frontend');
        const hasPrisma = extendedWorkflow?.technology?.backend?.orm === 'prisma';
        let content = `## Development\n\n`;
        content += `### Available Scripts\n\n`;
        if (hasBackend) {
            content += `**Backend:**\n\n`;
            content += `\`\`\`bash\n`;
            content += `cd backend\n\n`;
            content += `npm run dev          # Start development server with hot reload\n`;
            content += `npm run build        # Build for production\n`;
            content += `npm start            # Start production server\n`;
            content += `npm test             # Run tests\n`;
            if (hasPrisma) {
                content += `npm run prisma:generate  # Generate Prisma client\n`;
                content += `npm run prisma:migrate   # Run database migrations\n`;
                content += `npm run prisma:studio    # Open Prisma Studio (database GUI)\n`;
            }
            content += `\`\`\`\n\n`;
        }
        if (hasFrontend) {
            content += `**Frontend:**\n\n`;
            content += `\`\`\`bash\n`;
            content += `cd frontend\n\n`;
            content += `npm run dev          # Start development server\n`;
            content += `npm run build        # Build for production\n`;
            content += `npm run preview      # Preview production build\n`;
            content += `\`\`\`\n\n`;
        }
        if (hasPrisma) {
            content += `### Database Migrations\n\n`;
            content += `When you modify the Prisma schema:\n\n`;
            content += `\`\`\`bash\n`;
            content += `cd backend\n`;
            content += `npm run prisma:migrate\n`;
            content += `\`\`\`\n\n`;
        }
        return content;
    }
    generateDeployment(_workflow, _extendedWorkflow) {
        let content = `## Deployment\n\n`;
        content += `This application is containerized and ready for deployment to any platform that supports Docker.\n\n`;
        content += `### Building for Production\n\n`;
        content += `\`\`\`bash\n`;
        content += `# Build all services\n`;
        content += `docker-compose build\n\n`;
        content += `# Or build individually\n`;
        content += `cd backend && npm run build\n`;
        content += `cd frontend && npm run build\n`;
        content += `\`\`\`\n\n`;
        content += `### Deployment Platforms\n\n`;
        content += `This project can be deployed to:\n\n`;
        content += `- **AWS** (EC2, ECS, or App Runner)\n`;
        content += `- **Google Cloud Platform** (Cloud Run, GKE)\n`;
        content += `- **Azure** (Container Instances, AKS)\n`;
        content += `- **Railway** (easy one-click deployment)\n`;
        content += `- **Render** (supports Docker deployments)\n`;
        content += `- **DigitalOcean** (App Platform or Droplets)\n\n`;
        content += `### Environment Variables\n\n`;
        content += `Make sure to set all required environment variables in your deployment platform. `;
        content += `Refer to \`backend/.env.example\` for the complete list.\n\n`;
        return content;
    }
    generateFooter(workflow) {
        let content = `## Generated with Bangstack\n\n`;
        content += `This project was generated using [Bangstack](https://bangstack.com), `;
        content += `a workflow-to-code generator that transforms high-level workflow definitions into production-ready applications.\n\n`;
        content += `### Regenerating Code\n\n`;
        content += `To update or regenerate the code from the workflow:\n\n`;
        content += `\`\`\`bash\n`;
        content += `# Install Bangstack globally\n`;
        content += `npm install -g bangstack\n\n`;
        content += `# Regenerate from workflow file\n`;
        content += `bang generate ${workflow.workflow.id}.workflow.yaml --output .\n`;
        content += `\`\`\`\n\n`;
        content += `**⚠️ Note**: Regenerating will overwrite generated files. `;
        content += `Make sure to back up any manual changes or use version control.\n\n`;
        content += `---\n\n`;
        content += `**Generated on**: ${new Date().toISOString().split('T')[0]}\n`;
        content += `**Workflow**: ${workflow.workflow.id} v${workflow.workflow.version}\n`;
        return content;
    }
    capitalize(str) {
        return str.charAt(0).toUpperCase() + str.slice(1);
    }
}
exports.ReadmeGenerator = ReadmeGenerator;
//# sourceMappingURL=readme-generator.js.map