import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
import type { ID, Intent, IntentEvaluationRecord, IntentStatus, TrustLevel, TrustScore } from '../common/types.js';
import { type Config } from '../common/config.js';
import { type NewIntentEventRow, type NewIntentEvaluationRow, type NewIntentRow } from './schema.js';
/**
 * Dependencies for IntentRepository
 *
 * Use these to inject dependencies for testing or custom configurations.
 * If not provided, defaults to global singletons for backward compatibility.
 */
export interface IntentRepositoryDependencies {
    /** Drizzle database instance */
    database?: NodePgDatabase;
    /** Configuration (for encryption settings) */
    config?: Config;
}
/** Default page size when no limit is specified */
export declare const DEFAULT_PAGE_SIZE = 50;
/** Maximum allowed page size to prevent unbounded queries */
export declare const MAX_PAGE_SIZE = 1000;
/**
 * Paginated result with metadata for cursor/offset-based pagination
 */
export interface PaginatedResult<T> {
    /** The items in the current page */
    items: T[];
    /** Total count of matching items (if available) */
    total?: number;
    /** The limit used for this query */
    limit: number;
    /** The offset used for this query (for offset-based pagination) */
    offset?: number;
    /** Cursor for the next page (for cursor-based pagination) */
    nextCursor?: ID;
    /** Whether there are more items after this page */
    hasMore: boolean;
}
export interface ListIntentFilters {
    tenantId: ID;
    entityId?: ID;
    status?: IntentStatus;
    /** Page size limit (default: DEFAULT_PAGE_SIZE, max: MAX_PAGE_SIZE) */
    limit?: number;
    /** Offset for pagination (default: 0) */
    offset?: number;
    /** Cursor for pagination (intent ID) - mutually exclusive with offset */
    cursor?: ID;
    /** Pre-computed createdAt for cursor to skip lookup query */
    cursorCreatedAt?: Date;
    /** Include soft-deleted intents */
    includeDeleted?: boolean;
    /**
     * If true, throw an error when limit exceeds MAX_PAGE_SIZE instead of silently capping.
     * Default: false (silently cap to MAX_PAGE_SIZE for backwards compatibility)
     */
    strictLimitValidation?: boolean;
}
export interface IntentEventRecord {
    id: ID;
    intentId: ID;
    eventType: string;
    payload: Record<string, unknown>;
    occurredAt: string;
    hash?: string | null;
    previousHash?: string | null;
}
export declare class IntentRepository {
    private db;
    private encryptIfEnabled;
    /**
     * Create a new IntentRepository instance.
     *
     * @param deps - Optional dependencies for dependency injection.
     *               If not provided, uses global singletons (backward compatible).
     *
     * @example
     * // Default usage (backward compatible)
     * const repo = new IntentRepository();
     *
     * @example
     * // With dependency injection (for testing)
     * const repo = new IntentRepository({
     *   database: mockDb,
     *   config: testConfig,
     * });
     */
    constructor(deps?: IntentRepositoryDependencies);
    /**
     * Create intent with encryption and return the created intent
     */
    createIntent(data: NewIntentRow): Promise<Intent>;
    /**
     * Create intent within a transaction, including initial event
     */
    createIntentWithEvent(intentData: NewIntentRow, eventData: Omit<NewIntentEventRow, 'intentId'>): Promise<Intent>;
    /**
     * Create multiple intents in a single batch operation.
     *
     * This method provides optimized performance for bulk inserts by using
     * a single database transaction. Note that individual intents will not
     * have initial events recorded - use this for high-performance scenarios
     * where event tracking can be handled separately.
     *
     * @param intentsData - Array of intent data to insert
     * @returns Array of created intents
     */
    createIntentsBatch(intentsData: NewIntentRow[]): Promise<Intent[]>;
    findById(id: ID, tenantId: ID): Promise<Intent | null>;
    /**
     * Find by ID including soft-deleted (for audit purposes)
     */
    findByIdIncludeDeleted(id: ID, tenantId: ID): Promise<Intent | null>;
    findByDedupeHash(hash: string, tenantId: ID): Promise<Intent | null>;
    updateStatus(id: ID, tenantId: ID, status: IntentStatus): Promise<Intent | null>;
    /**
     * Cancel an intent with reason
     */
    cancelIntent(id: ID, tenantId: ID, reason: string): Promise<Intent | null>;
    /**
     * Soft delete an intent (GDPR compliant)
     */
    softDelete(id: ID, tenantId: ID): Promise<Intent | null>;
    /**
     * Permanently delete soft-deleted intents older than retention period
     * CRITICAL: Only deletes records where deletedAt IS NOT NULL to prevent accidental deletion
     */
    purgeDeletedIntents(retentionDays: number): Promise<number>;
    /**
     * List intents with cursor-based or offset-based pagination.
     * Enforces strict pagination limits to prevent unbounded queries.
     * Uses statement timeout to prevent long-running queries.
     *
     * @param filters - Query filters and pagination options
     * @returns Paginated result with items and pagination metadata
     * @throws VorionError if strictLimitValidation is true and limit > MAX_PAGE_SIZE
     * @throws StatementTimeoutError if the query exceeds the timeout
     */
    listIntents(filters: ListIntentFilters): Promise<PaginatedResult<Intent>>;
    /**
     * Record event with cryptographic hash for tamper detection
     */
    recordEvent(event: NewIntentEventRow): Promise<void>;
    /**
     * Get recent events for an intent with pagination limits.
     *
     * @param intentId - The intent ID to get events for
     * @param limit - Page size limit (default: DEFAULT_PAGE_SIZE, max: MAX_PAGE_SIZE)
     * @param offset - Offset for pagination (default: 0)
     * @returns Paginated result with events and pagination metadata
     */
    getRecentEvents(intentId: ID, limit?: number, offset?: number): Promise<PaginatedResult<IntentEventRecord>>;
    /**
     * Verify event chain integrity
     */
    verifyEventChain(intentId: ID): Promise<{
        valid: boolean;
        invalidAt?: number;
        error?: string;
    }>;
    updateTrustMetadata(intentId: ID, tenantId: ID, trustSnapshot: Record<string, unknown> | null, trustLevel?: TrustLevel, trustScore?: TrustScore): Promise<Intent | null>;
    recordEvaluation(evaluation: NewIntentEvaluationRow): Promise<IntentEvaluationRecord>;
    /**
     * List evaluations for an intent with pagination limits.
     *
     * @param intentId - The intent ID to get evaluations for
     * @param limit - Page size limit (default: DEFAULT_PAGE_SIZE, max: MAX_PAGE_SIZE)
     * @param offset - Offset for pagination (default: 0)
     * @returns Paginated result with evaluations and pagination metadata
     */
    listEvaluations(intentId: ID, limit?: number, offset?: number): Promise<PaginatedResult<IntentEvaluationRecord>>;
    countActiveIntents(tenantId: ID): Promise<number>;
    /**
     * Delete old events for retention compliance
     */
    deleteOldEvents(retentionDays: number): Promise<number>;
}
/**
 * Create a new IntentRepository instance with dependency injection.
 *
 * This is the preferred way to create repositories in production code
 * as it makes dependencies explicit and testable.
 *
 * @param deps - Optional dependencies. If not provided, uses global singletons.
 * @returns Configured IntentRepository instance
 *
 * @example
 * // Default usage (backward compatible)
 * const repo = createIntentRepository();
 *
 * @example
 * // With custom dependencies
 * const repo = createIntentRepository({
 *   database: customDb,
 *   config: customConfig,
 * });
 */
export declare function createIntentRepository(deps?: IntentRepositoryDependencies): IntentRepository;
//# sourceMappingURL=repository.d.ts.map