import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
import type { ID } from '../common/types.js';
import type { AuditRecord, CreateAuditRecordInput, AuditQueryFilters, AuditQueryResult, ChainIntegrityResult, AuditArchiveResult, AuditPurgeResult, AuditCleanupResult } from './types.js';
/**
 * Dependencies for AuditService
 *
 * Use these to inject dependencies for testing or custom configurations.
 * If not provided, defaults to global singletons for backward compatibility.
 */
export interface AuditServiceDependencies {
    /** Drizzle database instance */
    database?: NodePgDatabase;
}
/**
 * Audit Service class
 */
export declare class AuditService {
    private db;
    private injectedDb;
    /**
     * Create a new AuditService instance.
     *
     * @param deps - Optional dependencies for dependency injection.
     *               If not provided, uses global singletons (backward compatible).
     *
     * @example
     * // Default usage (backward compatible)
     * const service = new AuditService();
     *
     * @example
     * // With dependency injection (for testing)
     * const service = new AuditService({ database: mockDb });
     */
    constructor(deps?: AuditServiceDependencies);
    /**
     * Get the database instance (lazy initialization if not injected)
     */
    private getDb;
    /**
     * Record an audit event
     */
    record(input: CreateAuditRecordInput): Promise<AuditRecord>;
    /**
     * Query audit records with filters
     */
    query(filters: AuditQueryFilters): Promise<AuditQueryResult>;
    /**
     * Get a single audit record by ID
     */
    findById(id: ID, tenantId: ID): Promise<AuditRecord | null>;
    /**
     * Get audit records for a specific target
     */
    getForTarget(tenantId: ID, targetType: string, targetId: ID, options?: {
        limit?: number;
        offset?: number;
    }): Promise<AuditRecord[]>;
    /**
     * Get audit records for a specific trace
     */
    getByTrace(tenantId: ID, traceId: string): Promise<AuditRecord[]>;
    /**
     * Verify chain integrity for a tenant
     */
    verifyChainIntegrity(tenantId: ID, options?: {
        startSequence?: number;
        limit?: number;
    }): Promise<ChainIntegrityResult>;
    /**
     * Get audit statistics for a tenant
     */
    getStats(tenantId: ID, options?: {
        startTime?: string;
        endTime?: string;
    }): Promise<{
        totalRecords: number;
        byCategory: Record<string, number>;
        bySeverity: Record<string, number>;
        byOutcome: Record<string, number>;
    }>;
    /**
     * Convert database row to AuditRecord
     */
    private rowToAuditRecord;
    /**
     * Archive audit records older than specified days.
     * Archived records are marked but not deleted, preserving chain integrity.
     *
     * @param archiveAfterDays - Archive records older than this many days
     * @param batchSize - Number of records to process per batch
     * @returns Archive operation result
     */
    archiveOldRecords(archiveAfterDays: number, batchSize?: number): Promise<AuditArchiveResult>;
    /**
     * Permanently delete audit records older than the retention period.
     * Only deletes archived records to ensure recent records are preserved.
     *
     * IMPORTANT: This permanently removes data. Ensure compliance requirements
     * are met before calling this method.
     *
     * @param retentionDays - Delete records older than this many days
     * @param batchSize - Number of records to delete per batch
     * @returns Purge operation result
     */
    purgeOldRecords(retentionDays: number, batchSize?: number): Promise<AuditPurgeResult>;
    /**
     * Run full audit cleanup: archive old records, then purge expired ones.
     * This is the main entry point for scheduled audit maintenance.
     *
     * @param options - Cleanup configuration
     * @returns Combined cleanup result
     */
    runCleanup(options: {
        archiveAfterDays: number;
        retentionDays: number;
        batchSize?: number;
        archiveEnabled?: boolean;
    }): Promise<AuditCleanupResult>;
    /**
     * Get retention statistics for a tenant
     */
    getRetentionStats(tenantId: ID): Promise<{
        totalRecords: number;
        activeRecords: number;
        archivedRecords: number;
        oldestRecord?: string;
        newestRecord?: string;
        oldestArchived?: string;
    }>;
}
/**
 * Create a new audit service instance with dependency injection.
 *
 * This is the preferred way to create services in production code
 * as it makes dependencies explicit and testable.
 *
 * @param deps - Optional dependencies. If not provided, uses global singletons.
 * @returns Configured AuditService instance
 *
 * @example
 * // Default usage (backward compatible)
 * const service = createAuditService();
 *
 * @example
 * // With custom dependencies
 * const service = createAuditService({ database: customDb });
 */
export declare function createAuditService(deps?: AuditServiceDependencies): AuditService;
/**
 * Convenience function for recording common audit events
 */
export declare class AuditHelper {
    private service;
    constructor(service: AuditService);
    /**
     * Record an intent lifecycle event
     */
    recordIntentEvent(tenantId: ID, eventType: string, intentId: ID, actor: {
        type: 'user' | 'agent' | 'service' | 'system';
        id: ID;
        name?: string;
    }, options?: {
        outcome?: 'success' | 'failure' | 'partial';
        reason?: string;
        stateChange?: {
            before?: Record<string, unknown>;
            after?: Record<string, unknown>;
        };
        metadata?: Record<string, unknown>;
    }): Promise<AuditRecord>;
    /**
     * Record a policy evaluation event
     */
    recordPolicyEvaluation(tenantId: ID, policyId: ID, intentId: ID, actor: {
        type: 'user' | 'agent' | 'service' | 'system';
        id: ID;
    }, result: {
        action: string;
        matched: boolean;
        rulesEvaluated: number;
    }): Promise<AuditRecord>;
    /**
     * Record an escalation event
     */
    recordEscalationEvent(tenantId: ID, eventType: string, escalationId: ID, intentId: ID, actor: {
        type: 'user' | 'agent' | 'service' | 'system';
        id: ID;
        name?: string;
    }, options?: {
        outcome?: 'success' | 'failure' | 'partial';
        reason?: string;
        metadata?: Record<string, unknown>;
    }): Promise<AuditRecord>;
}
/**
 * Create an audit helper
 */
export declare function createAuditHelper(service: AuditService): AuditHelper;
//# sourceMappingURL=service.d.ts.map