// SPEC-597-EXEMPT: canonical mapping (npm-package↔framework, keyword catalogue)
// — must enumerate framework names by design; no detection logic to migrate.
// engine/local-first/storage-advisor.ts — SPEC-047
// Generates offline storage recommendations and schema evolution criteria.
/** Detect the target platform from framework and stack information. */
export function detectTargetPlatform(framework, stack) {
    const stackLower = stack.map((s) => s.toLowerCase()).join(' ');
    const fw = (framework ?? '').toLowerCase();
    if (fw.includes('react-native') || fw.includes('expo') || stackLower.includes('react-native')) {
        return 'mobile-rn';
    }
    if (fw.includes('flutter') || stackLower.includes('flutter')) {
        return 'mobile-flutter';
    }
    if (fw.includes('tauri') || stackLower.includes('tauri')) {
        return 'desktop-tauri';
    }
    if (fw.includes('electron') || stackLower.includes('electron')) {
        return 'desktop-electron';
    }
    return 'web';
}
/** Get storage recommendation by platform. */
export function getStorageRecommendation(platform) {
    const DEFAULT_REC = {
        engine: 'IndexedDB (native browser API)',
        reason: 'No extra dependencies required — use idb or Dexie.js as wrappers',
        alternative: 'wa-sqlite / SQLite WASM (OPFS) for complex relational queries',
    };
    const recommendations = {
        web: DEFAULT_REC,
        'mobile-rn': {
            engine: 'expo-sqlite',
            reason: 'First-party Expo SQLite with async API and WAL mode support',
            alternative: 'op-sqlite for maximum performance (C++ bindings)',
        },
        'mobile-flutter': {
            engine: 'sqflite',
            reason: 'Standard SQLite plugin for Flutter — well maintained, iOS/Android',
            alternative: 'drift (type-safe reactive SQLite for Flutter)',
        },
        'desktop-tauri': {
            engine: 'SQLite via tauri-plugin-sql',
            reason: 'Direct SQLite access via Tauri Rust plugin — same database as the OS',
            alternative: 'rusqlite in Rust sidecar for complex queries',
        },
        'desktop-electron': {
            engine: 'better-sqlite3',
            reason: 'Synchronous SQLite for Node.js/Electron — fastest JS SQLite binding',
            alternative: 'electron-store for simple key-value (not relational)',
        },
    };
    return recommendations[platform] ?? DEFAULT_REC;
}
/** Generate offline PWA/storage criteria for HU.md. */
export function generateOfflineCriteria(storageEngine, platform) {
    const lines = ['', '## Offline Storage', ''];
    const recommendation = getStorageRecommendation(platform);
    lines.push('- [ ] **Core Offline Operations**: La app funciona completamente sin conexión para operaciones core (crear, editar, ver)');
    lines.push(`- [ ] **Local Persistence**: Los datos se persisten en ${recommendation.engine} con schema versionado`);
    if (platform === 'web') {
        lines.push('- [ ] **Service Worker**: Service Worker intercepta fetch requests y responde del cache cuando offline');
        lines.push('- [ ] **PWA Manifest**: La app tiene Web App Manifest con `display: standalone` y íconos de 192x192 y 512x512');
    }
    if (storageEngine === 'IndexedDB' || platform === 'web') {
        lines.push('- [ ] **IndexedDB Schema Version**: El schema de IndexedDB tiene versión numérica y las migraciones se ejecutan en `onupgradeneeded`');
    }
    lines.push('');
    return lines;
}
/** Generate schema evolution criteria for HU.md. */
export function generateSchemaEvolutionCriteria() {
    return [
        {
            title: 'Backward-Compatible Migrations',
            body: 'Las migraciones de schema son incrementales y backward-compatible — un cliente en versión 2.0 puede abrir un documento creado con 1.0',
        },
        {
            title: 'Schema Version Tracking',
            body: 'El schema tiene versión semántica y las migraciones se ejecutan automáticamente al abrir un documento antiguo',
        },
        {
            title: 'CRDT Schema Documentation',
            body: 'El schema de CRDT (tipos de datos, estructura de documento) está documentado y versionado en el repositorio',
        },
    ];
}
/** Format schema evolution criteria as HU.md lines. */
export function formatSchemaEvolutionAsLines(criteria) {
    const lines = ['', '## Schema Evolution', ''];
    for (const c of criteria) {
        lines.push(`- [ ] **${c.title}**: ${c.body}`);
    }
    lines.push('');
    return lines;
}
/** Generate UX sync state criteria for HU.md. */
export function generateUxSyncStateCriteria() {
    return [
        '',
        '## UX — Sync State',
        '',
        '- [ ] **Sync Indicator**: La UI muestra indicador de sync state (synced/pending/conflict/offline) — el usuario siempre sabe el estado de sus datos',
        '- [ ] **Optimistic UI**: Las operaciones optimistas se muestran inmediatamente con estado "pending" — sin bloquear al usuario hasta que el server confirme',
        '- [ ] **Conflict Notification**: Los conflictos no resolubles se notifican al usuario con opción de resolución manual (no se silencian automáticamente)',
        '',
    ];
}
//# sourceMappingURL=storage-advisor.js.map