// Planu — Diagram Generators
// Generates Mermaid diagrams from project knowledge and specs
export function generateArchitectureDiagram(knowledge) {
    const arch = knowledge.architecture;
    const lines = ['graph TB'];
    for (const layer of arch.layers) {
        const id = layer.name.replace(/[^a-zA-Z0-9]/g, '_');
        lines.push(`  ${id}["${layer.name}\\n${layer.directories.join(', ')}"]`);
    }
    // Add dependency arrows
    for (const layer of arch.layers) {
        const fromId = layer.name.replace(/[^a-zA-Z0-9]/g, '_');
        for (const dep of layer.dependsOn) {
            const toId = dep.replace(/[^a-zA-Z0-9]/g, '_');
            lines.push(`  ${fromId} --> ${toId}`);
        }
    }
    return {
        type: 'architecture',
        title: `${arch.primary} Architecture`,
        format: 'mermaid',
        content: lines.join('\n'),
        description: `Architecture diagram showing ${arch.primary} pattern with ${arch.layers.length} layers.`,
    };
}
export function generateComponentDiagram(knowledge) {
    const lines = ['graph LR'];
    for (const app of knowledge.apps) {
        const id = app.name.replace(/[^a-zA-Z0-9]/g, '_');
        lines.push(`  ${id}["${app.name}\\n${app.type}\\n${app.language}"]`);
    }
    // Connect frontend to backend
    const frontends = knowledge.apps.filter((a) => a.type === 'frontend');
    const backends = knowledge.apps.filter((a) => a.type === 'backend');
    for (const fe of frontends) {
        for (const be of backends) {
            const feId = fe.name.replace(/[^a-zA-Z0-9]/g, '_');
            const beId = be.name.replace(/[^a-zA-Z0-9]/g, '_');
            lines.push(`  ${feId} --> ${beId}`);
        }
    }
    return {
        type: 'component',
        title: 'Component Diagram',
        format: 'mermaid',
        content: lines.join('\n'),
        description: `Component diagram with ${knowledge.apps.length} app(s).`,
    };
}
export function generateDataFlowDiagram(knowledge) {
    const lines = ['graph LR'];
    lines.push('  User((User))');
    lines.push('  UI[UI Layer]');
    lines.push('  API[API Layer]');
    lines.push('  Logic[Business Logic]');
    if (knowledge.database !== 'unknown') {
        lines.push(`  DB[(${knowledge.database})]`);
        lines.push('  Logic --> DB');
    }
    lines.push('  User --> UI');
    lines.push('  UI --> API');
    lines.push('  API --> Logic');
    return {
        type: 'data-flow',
        title: 'Data Flow',
        format: 'mermaid',
        content: lines.join('\n'),
        description: 'High-level data flow through the application.',
    };
}
export function generateSequenceDiagram(spec) {
    const lines = ['sequenceDiagram'];
    const title = spec?.title ?? 'Request Flow';
    lines.push('  actor User');
    lines.push('  participant UI');
    lines.push('  participant API');
    lines.push('  participant Service');
    lines.push('  participant DB');
    lines.push('');
    lines.push(`  User->>UI: ${title}`);
    lines.push('  UI->>API: HTTP Request');
    lines.push('  API->>Service: Process');
    lines.push('  Service->>DB: Query');
    lines.push('  DB-->>Service: Result');
    lines.push('  Service-->>API: Response');
    lines.push('  API-->>UI: JSON');
    lines.push('  UI-->>User: Display');
    return {
        type: 'sequence',
        title: `Sequence: ${title}`,
        format: 'mermaid',
        content: lines.join('\n'),
        description: `Sequence diagram for ${title}.`,
    };
}
export function generateErDiagram(knowledge) {
    const lines = ['erDiagram'];
    // Placeholder ER — real implementation would parse schema files
    lines.push('  USERS {');
    lines.push('    uuid id PK');
    lines.push('    string email');
    lines.push('    timestamp created_at');
    lines.push('  }');
    return {
        type: 'er',
        title: 'Entity Relationship Diagram',
        format: 'mermaid',
        content: lines.join('\n'),
        description: `ER diagram for ${knowledge.database} database. Update with actual schema.`,
    };
}
export function generateStateMachineDiagram(spec) {
    const lines = ['stateDiagram-v2'];
    if (spec) {
        lines.push(`  [*] --> draft`);
        lines.push(`  draft --> review: Submit`);
        lines.push(`  review --> approved: Approve`);
        lines.push(`  review --> draft: Request Changes`);
        lines.push(`  approved --> implementing: Start`);
        lines.push(`  implementing --> done: Complete`);
        lines.push(`  done --> [*]`);
    }
    else {
        lines.push(`  [*] --> Created`);
        lines.push(`  Created --> Active: Activate`);
        lines.push(`  Active --> Completed: Complete`);
        lines.push(`  Completed --> [*]`);
    }
    return {
        type: 'state-machine',
        title: 'State Machine',
        format: 'mermaid',
        content: lines.join('\n'),
        description: 'State machine diagram showing lifecycle transitions.',
    };
}
export function generateDependencyDiagram(knowledge) {
    const lines = ['graph TD'];
    for (const layer of knowledge.architecture.layers) {
        const id = layer.name.replace(/[^a-zA-Z0-9]/g, '_');
        lines.push(`  ${id}[${layer.name}]`);
    }
    for (const layer of knowledge.architecture.layers) {
        const fromId = layer.name.replace(/[^a-zA-Z0-9]/g, '_');
        for (const dep of layer.dependsOn) {
            const toId = dep.replace(/[^a-zA-Z0-9]/g, '_');
            lines.push(`  ${fromId} -.-> ${toId}`);
        }
        for (const forbidden of layer.neverDependsOn) {
            const toId = forbidden.replace(/[^a-zA-Z0-9]/g, '_');
            lines.push(`  ${fromId} -.-x ${toId}`);
        }
    }
    return {
        type: 'dependency',
        title: 'Dependency Rules',
        format: 'mermaid',
        content: lines.join('\n'),
        description: 'Dependency rules: dashed arrows = allowed, crossed = forbidden.',
    };
}
export function generateDeploymentDiagram(knowledge) {
    const lines = ['graph LR'];
    const units = knowledge.architecture.deploymentUnits;
    lines.push('  Dev[Developer]');
    lines.push('  Git[Git Repository]');
    lines.push('  Dev --> Git');
    for (const unit of units) {
        const id = unit.replace(/[^a-zA-Z0-9]/g, '_');
        lines.push(`  ${id}[${unit}]`);
        lines.push(`  Git --> ${id}`);
    }
    return {
        type: 'deployment',
        title: 'Deployment Pipeline',
        format: 'mermaid',
        content: lines.join('\n'),
        description: `Deployment pipeline with ${units.length} target(s).`,
    };
}
//# sourceMappingURL=diagrams.js.map