import { patterns } from './core.js';
/**
 * Infers the applicable privacy framework from project context.
 * Falls back to GDPR (most restrictive) if framework cannot be determined.
 */
export function detectLegalFramework(projectContext) {
    const { region, existingText = '' } = projectContext;
    const lowerText = existingText.toLowerCase();
    if (region) {
        const upperRegion = region.toUpperCase();
        if (['EU', 'EEA', 'UK', 'DE', 'FR', 'ES', 'IT', 'NL', 'PL'].includes(upperRegion)) {
            return 'GDPR';
        }
        if (upperRegion === 'BR') {
            return 'LGPD';
        }
        if (['US-CA', 'CA', 'CALIFORNIA'].includes(upperRegion)) {
            return 'CCPA';
        }
        if (upperRegion === 'CANADA') {
            return 'PIPEDA';
        }
        if (['TH', 'SG', 'THAILAND', 'SINGAPORE'].includes(upperRegion)) {
            return 'PDPA';
        }
    }
    if (lowerText.includes('lgpd') || lowerText.includes('brazil') || lowerText.includes('brasil')) {
        return 'LGPD';
    }
    if (lowerText.includes('ccpa') || lowerText.includes('california')) {
        return 'CCPA';
    }
    if (lowerText.includes('gdpr') || lowerText.includes('rgpd') || lowerText.includes('europe')) {
        return 'GDPR';
    }
    return 'GDPR';
}
/**
 * Generates a RetentionPolicy for a set of detected PII fields under a given framework.
 */
export function generateRetentionPolicy(piiFields, framework) {
    const frameworkKey = framework === 'custom' ? 'GDPR' : framework;
    const config = patterns.frameworks[frameworkKey];
    /* v8 ignore start */
    const defaultRetention = config?.defaultRetentionDays ?? 730;
    /* v8 ignore stop */
    const triggers = ['time-expiry', 'user-request'];
    const hasSensitiveSpecial = piiFields.some((f) => f.isSensitiveSpecial);
    if (hasSensitiveSpecial) {
        triggers.push('consent-withdrawal');
    }
    const hasFinancial = piiFields.some((f) => f.category === 'financial');
    const legalMinimumDays = hasFinancial ? 1825 : undefined;
    const propagationSystems = [
        'primary-database',
        'backups',
        'application-logs',
        'caches',
        'third-party-processors',
    ];
    return {
        retentionPeriodDays: defaultRetention,
        triggers,
        deletionType: hasSensitiveSpecial ? 'physical' : 'logical',
        propagationSystems,
        verificationRequired: hasSensitiveSpecial || hasFinancial,
        legalMinimumDays,
    };
}
//# sourceMappingURL=legal-framework.js.map