"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GitBranchPreGenerator = void 0;
class GitBranchPreGenerator {
    intentPatterns = {
        feature: { files: ['model', 'service', 'routes', 'tests'], description: 'New feature' },
        fix: { files: ['tests', 'fix'], description: 'Bug fix' },
        bugfix: { files: ['tests', 'fix'], description: 'Bug fix' },
        refactor: { files: ['tests', 'refactored'], description: 'Code refactor' },
        chore: { files: ['config', 'deps'], description: 'Maintenance' },
        docs: { files: ['readme'], description: 'Documentation' },
        test: { files: ['tests'], description: 'Testing' },
        perf: { files: ['benchmark', 'optimized'], description: 'Performance' },
        security: { files: ['audit', 'fix'], description: 'Security' },
    };
    parseBranchName(branchName) {
        const cleaned = branchName.replace(/^(origin\/|remotes\/)/, '');
        const parts = cleaned.split('/');
        let type = 'feature';
        let name = cleaned;
        if (parts.length >= 2) {
            const prefix = parts[0].toLowerCase();
            if (this.intentPatterns[prefix]) {
                type = prefix;
                name = parts.slice(1).join('-');
            }
        }
        const intent = name
            .replace(/[-_]/g, ' ')
            .replace(/\b\w/g, (c) => c.toUpperCase());
        return { type, name, intent };
    }
    generateFiles(branchName, patterns, language = 'typescript') {
        const { type, name, intent } = this.parseBranchName(branchName);
        const intentConfig = this.intentPatterns[type] || this.intentPatterns['feature'];
        const files = [];
        const ext = this.getExtension(language);
        if (intentConfig.files.includes('model')) {
            files.push({
                path: `src/models/${this.toFileName(name)}.${ext}`,
                content: this.generateModel(name, intent, patterns, language),
                type: 'model',
            });
        }
        if (intentConfig.files.includes('tests')) {
            files.push({
                path: `src/__tests__/${this.toFileName(name)}.test.${ext}`,
                content: this.generateTest(name, intent, patterns, language),
                type: 'test',
            });
        }
        if (intentConfig.files.includes('readme')) {
            files.push({
                path: `docs/${this.toFileName(name)}.md`,
                content: this.generateReadme(name, intent),
                type: 'readme',
            });
        }
        return files;
    }
    getIntentSummary(branchName) {
        const { type, intent } = this.parseBranchName(branchName);
        const config = this.intentPatterns[type] || this.intentPatterns['feature'];
        return `${config.description}: ${intent}. Will generate: ${config.files.join(', ')}.`;
    }
    generateModel(name, intent, patterns, language) {
        const className = this.toPascalCase(name);
        const useTypes = patterns.some((p) => p.category === 'type_annotation');
        if (language === 'typescript' && useTypes) {
            return `export interface ${className} {\n  id: string;\n  createdAt: Date;\n  updatedAt: Date;\n}\n`;
        }
        return `// ${intent} - Model\n// TODO: Define ${className} schema\n`;
    }
    generateTest(_name, intent, _patterns, _language) {
        const componentName = this.toPascalCase(_name);
        return `import { describe, it, expect } from 'vitest';\n\ndescribe('${componentName}', () => {\n  it('should handle ${intent.toLowerCase()}', () => {\n    // TODO: Add test cases\n    expect(true).toBe(true);\n  });\n});\n`;
    }
    generateReadme(_name, intent) {
        return `# ${intent}\n\n## Overview\n\nTODO: Describe the ${intent.toLowerCase()} feature.\n\n## Usage\n\n\`\`\`typescript\n// TODO: Add usage examples\n\`\`\`\n`;
    }
    toFileName(name) {
        return name.toLowerCase().replace(/\s+/g, '-');
    }
    toPascalCase(name) {
        return name
            .replace(/[-_]/g, ' ')
            .replace(/\b\w/g, (c) => c.toUpperCase())
            .replace(/\s+/g, '');
    }
    getExtension(language) {
        switch (language) {
            case 'typescript': return 'ts';
            case 'javascript': return 'js';
            case 'python': return 'py';
            default: return 'ts';
        }
    }
}
exports.GitBranchPreGenerator = GitBranchPreGenerator;
//# sourceMappingURL=git-branch-pregenerator.js.map