// tools/challenge-spec/scenarios-data.ts — Data consistency and partial write scenarios
import { contentMentions } from './scenarios-utils.js';
export function generateDataConsistencyScenarios(_spec, content, _knowledge) {
    const scenarios = [];
    const lower = content.toLowerCase();
    // Partial writes
    if (lower.includes('transaction') ||
        lower.includes('update') ||
        lower.includes('create') ||
        lower.includes('modify') ||
        lower.includes('save')) {
        scenarios.push({
            scenario: 'Partial write: server crashes mid-transaction',
            probability: 'low',
            impact: 'critical',
            currentHandling: contentMentions(lower, ['transaction', 'atomic', 'rollback'])
                ? 'Transactions mentioned'
                : 'Not addressed',
            requiredHandling: 'Wrap multi-step writes in database transactions. Implement saga pattern for distributed operations.',
            dataConsistency: 'ACID properties must be maintained. No orphaned records.',
            userExperience: 'Transparent: user sees either success or clean failure with clear error message.',
        });
    }
    // Stale data
    if (lower.includes('cache') || lower.includes('real-time') || lower.includes('concurrent')) {
        scenarios.push({
            scenario: 'Stale data served from cache after underlying data changes',
            probability: 'high',
            impact: 'medium',
            currentHandling: contentMentions(lower, ['invalidat', 'ttl', 'websocket', 'real-time'])
                ? 'Some cache strategy mentioned'
                : 'Not addressed',
            requiredHandling: 'Implement cache invalidation on writes. Use TTL for time-sensitive data. Consider event-driven invalidation.',
            dataConsistency: 'Define acceptable staleness window per data type. Document cache strategy.',
            userExperience: 'Show "last updated" timestamp. Offer manual refresh option.',
        });
    }
    // Duplicate operations
    scenarios.push({
        scenario: 'User double-clicks submit, causing duplicate records',
        probability: 'high',
        impact: 'medium',
        currentHandling: contentMentions(lower, ['idempoten', 'debounce', 'disable', 'lock'])
            ? 'Some prevention mentioned'
            : 'Not addressed',
        requiredHandling: 'Implement idempotency keys for mutations. Disable submit button on click. Use unique constraints in DB.',
        dataConsistency: 'No duplicate records from repeated submissions.',
        userExperience: 'Button disabled during submission. Clear success/error feedback.',
    });
    return scenarios;
}
//# sourceMappingURL=scenarios-data.js.map