"use strict";
/**
 * Base Documentation Template
 * Abstract class for all documentation templates
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.DocumentationTemplate = void 0;
class DocumentationTemplate {
    /**
     * Get output filename for this documentation
     */
    getOutputPath(intent) {
        if (intent.outputPath) {
            return intent.outputPath;
        }
        // Default path based on type and scope
        const filename = intent.scope
            ? `${intent.type}-${this.slugify(intent.scope)}.md`
            : `${intent.type}.md`;
        return filename;
    }
    /**
     * Helper: Convert string to slug
     */
    slugify(text) {
        return text
            .toLowerCase()
            .replace(/[^\w\s-]/g, '')
            .replace(/\s+/g, '-')
            .replace(/-+/g, '-')
            .trim();
    }
    /**
     * Helper: Capitalize first letter
     */
    capitalize(text) {
        return text.charAt(0).toUpperCase() + text.slice(1);
    }
    /**
     * Helper: Get technology display name
     */
    getTechnologyName(technology) {
        const names = {
            react: 'React',
            express: 'Express',
            'typescript-express': 'Express.js',
            prisma: 'Prisma',
            clerk: 'Clerk',
            auth0: 'Auth0',
            postgresql: 'PostgreSQL',
            mysql: 'MySQL',
            mongodb: 'MongoDB',
            redis: 'Redis',
        };
        return names[technology] || this.capitalize(technology);
    }
    /**
     * Helper: Format version for display
     */
    formatVersion(version) {
        return version.replace(/^[\^~>=<]+/, '');
    }
    /**
     * Helper: Generate footer with generation metadata
     */
    generateFooter(context) {
        const { workflow } = context;
        let footer = '\n---\n\n';
        // Add version information if available
        const techVersions = this.getRelevantVersions(context);
        if (techVersions.length > 0) {
            footer += `*Auto-generated based on: ${techVersions.join(', ')}*\n\n`;
        }
        footer += `*Generated from workflow: ${workflow.workflow.id} v${workflow.workflow.version}*\n`;
        return footer;
    }
    /**
     * Helper: Get relevant technology versions for footer
     */
    getRelevantVersions(context) {
        const { versions, extendedWorkflow } = context;
        const techVersions = [];
        // Add frontend framework version
        if (extendedWorkflow?.technology?.frontend?.framework) {
            const framework = extendedWorkflow.technology.frontend.framework;
            const version = this.getVersionForFramework(framework, versions);
            if (version) {
                techVersions.push(`${this.getTechnologyName(framework)} ${this.formatVersion(version)}`);
            }
        }
        // Add backend framework version
        if (extendedWorkflow?.technology?.backend?.framework) {
            const framework = extendedWorkflow.technology.backend.framework;
            const version = this.getVersionForFramework(framework, versions);
            if (version) {
                techVersions.push(`${this.getTechnologyName(framework)} ${this.formatVersion(version)}`);
            }
        }
        // Add auth provider version
        if (extendedWorkflow?.auth?.provider) {
            const provider = extendedWorkflow.auth.provider;
            const version = this.getVersionForAuth(provider, versions);
            if (version) {
                techVersions.push(`${this.getTechnologyName(provider)} ${this.formatVersion(version)}`);
            }
        }
        return techVersions;
    }
    /**
     * Helper: Get version for a framework
     */
    getVersionForFramework(framework, versions) {
        const packageNames = {
            react: 'react',
            express: 'express',
            fastify: 'fastify',
            nestjs: '@nestjs/core',
        };
        const packageName = packageNames[framework];
        if (!packageName)
            return undefined;
        // Search all components
        for (const versionMap of Object.values(versions)) {
            if (!versionMap)
                continue;
            const version = versionMap.dependencies[packageName] || versionMap.devDependencies[packageName];
            if (version)
                return version;
        }
        return undefined;
    }
    /**
     * Helper: Get version for auth provider
     */
    getVersionForAuth(provider, versions) {
        const packageNames = {
            clerk: '@clerk/express',
            auth0: 'express-oauth2-jwt-bearer',
        };
        const packageName = packageNames[provider];
        if (!packageName)
            return undefined;
        // Search all components
        for (const versionMap of Object.values(versions)) {
            if (!versionMap)
                continue;
            const version = versionMap.dependencies[packageName] || versionMap.devDependencies[packageName];
            if (version)
                return version;
        }
        return undefined;
    }
}
exports.DocumentationTemplate = DocumentationTemplate;
//# sourceMappingURL=base-template.js.map