// SPDX-License-Identifier: Apache-2.0
// Copyright 2024-2026 Vorion LLC
/**
 * Data Retention Policy Definitions
 *
 * Defines retention policies for different data types to ensure
 * GDPR compliance and proper data lifecycle management.
 *
 * @packageDocumentation
 */
import { z } from 'zod';
/**
 * Default retention policies
 *
 * These values are based on common compliance requirements:
 * - GDPR: Right to erasure, generally 30 days for failed/denied
 * - SOC2: Audit logs must be retained for 2 years
 * - Legal: Financial proofs often require 7-year retention
 */
export const DEFAULT_RETENTION_POLICIES = {
    intents: {
        approved: 90, // 90 days for approved intents
        denied: 90, // 90 days for denied intents
        failed: 30, // 30 days for GDPR compliance
        escalated: 180, // 180 days for escalated intents (may need longer review)
    },
    auditLogs: 730, // 2 years (SOC2 requirement)
    proofs: 2555, // 7 years (legal/financial compliance)
    sessions: 30, // 30 days for session data
    apiKeyLogs: 90, // 90 days for API key access logs
};
/**
 * Retention policy schema for validation
 */
export const retentionPolicySchema = z.object({
    intents: z.object({
        approved: z.number().int().min(1).max(3650),
        denied: z.number().int().min(1).max(3650),
        failed: z.number().int().min(1).max(3650),
        escalated: z.number().int().min(1).max(3650),
    }),
    auditLogs: z.number().int().min(1).max(3650),
    proofs: z.number().int().min(1).max(3650),
    sessions: z.number().int().min(1).max(3650),
    apiKeyLogs: z.number().int().min(1).max(3650),
});
/**
 * Schema for creating a litigation hold
 */
export const createLitigationHoldSchema = z.object({
    matterReference: z.string().min(1).max(255),
    description: z.string().min(1).max(2000),
    dataType: z.enum(['intent', 'audit_log', 'proof', 'session', 'api_key_log', 'all']),
    entityIds: z.array(z.string().uuid()).optional(),
    expiresAt: z.string().datetime().optional(),
});
/**
 * Schema for releasing a litigation hold
 */
export const releaseLitigationHoldSchema = z.object({
    releaseReason: z.string().min(1).max(2000),
});
// =============================================================================
// HELPER FUNCTIONS
// =============================================================================
/**
 * Get the retention period for a specific intent status
 */
export function getIntentRetentionPeriod(status, config = DEFAULT_RETENTION_POLICIES) {
    const statusKey = status.toLowerCase();
    return config.intents[statusKey] ?? config.intents.approved;
}
/**
 * Calculate the cutoff date for retention
 */
export function getRetentionCutoffDate(retentionDays) {
    const cutoff = new Date();
    cutoff.setDate(cutoff.getDate() - retentionDays);
    return cutoff;
}
/**
 * Check if a date is past the retention period
 */
export function isPastRetention(recordDate, retentionDays) {
    const date = typeof recordDate === 'string' ? new Date(recordDate) : recordDate;
    const cutoff = getRetentionCutoffDate(retentionDays);
    return date < cutoff;
}
/**
 * Merge custom retention policies with defaults
 */
export function mergeRetentionPolicies(custom) {
    return {
        intents: {
            ...DEFAULT_RETENTION_POLICIES.intents,
            ...custom.intents,
        },
        auditLogs: custom.auditLogs ?? DEFAULT_RETENTION_POLICIES.auditLogs,
        proofs: custom.proofs ?? DEFAULT_RETENTION_POLICIES.proofs,
        sessions: custom.sessions ?? DEFAULT_RETENTION_POLICIES.sessions,
        apiKeyLogs: custom.apiKeyLogs ?? DEFAULT_RETENTION_POLICIES.apiKeyLogs,
    };
}
//# sourceMappingURL=retention-policy.js.map