// engine/mermaid/diagram-generators.ts — Individual diagram type generators.
// Extracted from mermaid-generator.ts to keep file sizes within limits.
import { buildParticipants } from './helpers.js';
/**
 * Generate an ER diagram for database changes.
 */
export function generateErDiagram(spec, knowledge) {
    const dbEngine = knowledge?.database ?? 'unknown';
    const lines = [
        'erDiagram',
        `  %% Database: ${dbEngine}`,
        `  %% Spec: ${spec.title}`,
        '  ENTITY_A {',
        '    string id PK',
        '    string name',
        '    datetime created_at',
        '  }',
        '  ENTITY_B {',
        '    string id PK',
        '    string entity_a_id FK',
        '    string value',
        '  }',
        '  ENTITY_A ||--o{ ENTITY_B : "has many"',
    ];
    return {
        type: 'er',
        title: `Entity Relationship — ${spec.title}`,
        format: 'mermaid',
        content: lines.join('\n'),
        description: 'Entity-relationship diagram for database schema changes. Customize entities to match your domain.',
    };
}
/**
 * Generate a sequence diagram for cross-module interactions.
 */
export function generateSequenceDiagram(spec, knowledge) {
    const participants = buildParticipants(spec.target, knowledge);
    const lines = ['sequenceDiagram'];
    for (const p of participants) {
        lines.push(`  participant ${p.id} as ${p.label}`);
    }
    // Generate basic request-response flow
    const first = participants[0];
    const second = participants[1];
    if (first && second) {
        lines.push(`  ${first.id}->>+${second.id}: Request`);
        const third = participants[2];
        if (third) {
            lines.push(`  ${second.id}->>+${third.id}: Process`);
            lines.push(`  ${third.id}-->>-${second.id}: Result`);
        }
        lines.push(`  ${second.id}-->>-${first.id}: Response`);
    }
    return {
        type: 'sequence',
        title: `Sequence Diagram — ${spec.title}`,
        format: 'mermaid',
        content: lines.join('\n'),
        description: 'Sequence diagram showing interactions between modules. Customize messages to match your flow.',
    };
}
/**
 * Generate a component diagram for UI specs.
 */
export function generateComponentDiagram(spec, knowledge) {
    const framework = knowledge?.framework ?? 'UI';
    const lines = [
        'graph TD',
        `  Page["${spec.title} Page"]`,
        `  Page --> Header[Header]`,
        `  Page --> Main[Main Content]`,
        `  Page --> Footer[Footer]`,
        `  Main --> CompA["Component A"]`,
        `  Main --> CompB["Component B"]`,
        `  CompA --> Store["${framework} State"]`,
        `  CompB --> Store`,
    ];
    return {
        type: 'component',
        title: `Component Diagram — ${spec.title}`,
        format: 'mermaid',
        content: lines.join('\n'),
        description: 'UI component hierarchy diagram. Customize components to match your design.',
    };
}
/**
 * Generate a state machine diagram for transitions.
 */
export function generateStateDiagram(spec) {
    const lines = [
        'stateDiagram-v2',
        `  [*] --> Initial`,
        `  Initial --> Processing: Start`,
        `  Processing --> Success: Complete`,
        `  Processing --> Error: Fail`,
        `  Error --> Processing: Retry`,
        `  Success --> [*]`,
    ];
    return {
        type: 'state-machine',
        title: `State Machine — ${spec.title}`,
        format: 'mermaid',
        content: lines.join('\n'),
        description: 'State machine diagram showing state transitions. Customize states to match your domain.',
    };
}
/**
 * Generate an architecture diagram for architectural specs.
 */
export function generateArchitectureDiagram(spec, knowledge) {
    const arch = knowledge?.architecture;
    const pattern = arch ? arch.primary : 'layered';
    const externalServices = knowledge?.externalServices ?? [];
    const externalLabel = externalServices.length > 0 ? externalServices.slice(0, 2).join(' / ') : 'External Services';
    const lines = [
        'graph TB',
        `  subgraph "${spec.title}"`,
        `    direction TB`,
        `    Client["Client Layer"]`,
        `    API["API Gateway"]`,
        `    Service["Service Layer"]`,
        `    Data["Data Layer"]`,
        `    Client --> API`,
        `    API --> Service`,
        `    Service --> Data`,
        `  end`,
        `  External["${externalLabel}"]`,
        `  Service --> External`,
        `  %% Architecture: ${pattern}`,
    ];
    return {
        type: 'architecture',
        title: `Architecture — ${spec.title}`,
        format: 'mermaid',
        content: lines.join('\n'),
        description: `Architecture diagram using ${pattern} pattern. Customize to match your system.`,
    };
}
//# sourceMappingURL=diagram-generators.js.map