import { OnModuleInit, OnModuleDestroy } from '@nestjs/common';
import { DrizzleClient } from '../../types/drizzle.js';
import { ICacheService } from './cache.protocol.js';
export { CACHE_DEFAULT_TTL } from './cache.tokens.js';
import 'drizzle-orm/node-postgres';

/**
 * DrizzleCacheService — Postgres-backed ICacheService via Drizzle ORM.
 *
 * Storage: `cache_entries` table with key (text pk), value (jsonb), expiresAt (timestamp).
 * TTL enforcement: reads filter by `expiresAt > now() OR expiresAt IS NULL`.
 * Prefix invalidation: `DELETE WHERE key LIKE 'escaped_prefix%'`.
 *
 * Lifecycle:
 * - OnModuleInit: starts periodic cleanup of expired entries.
 *   Uses the Jobs subsystem if available (optional injection); falls back to setInterval.
 * - OnModuleDestroy: clears the setInterval timer if used.
 *
 * Error behavior per ADR-008:
 * - get() / has() return null/false on any error (never throw for reads).
 * - set() / delete() / invalidateByPrefix() throw on failure.
 */

declare class DrizzleCacheService implements ICacheService, OnModuleInit, OnModuleDestroy {
    private readonly db;
    private readonly defaultTtl;
    private cleanupTimer;
    /** In-flight getOrSet promises — keyed by cache key to deduplicate stampedes. */
    private readonly inflight;
    constructor(db: DrizzleClient, defaultTtl?: number | null);
    onModuleInit(): Promise<void>;
    onModuleDestroy(): Promise<void>;
    get<T = unknown>(key: string): Promise<T | null>;
    set<T = unknown>(key: string, value: T, ttlSeconds?: number): Promise<void>;
    delete(key: string): Promise<void>;
    invalidateByPrefix(prefix: string): Promise<number>;
    has(key: string): Promise<boolean>;
    getOrSet<T = unknown>(key: string, factory: () => Promise<T>, ttlSeconds?: number): Promise<T>;
    /** Remove all expired entries. Called by the cleanup timer. */
    private deleteExpired;
}

export { DrizzleCacheService };
