/**
 * Database Circuit Breaker and Resilience
 *
 * Provides circuit breaker protection for database operations to prevent
 * cascading failures when the database is unavailable or degraded.
 *
 * Features:
 * - Circuit breaker with CLOSED -> OPEN -> HALF_OPEN states
 * - Configurable failure threshold and reset timeout
 * - Statement timeout enforcement via PostgreSQL
 * - Metrics export for monitoring
 * - Graceful degradation support
 *
 * @packageDocumentation
 */
import { CircuitState, CircuitBreakerOpenError } from './circuit-breaker.js';
import type { CircuitBreaker } from './circuit-breaker.js';
export { CircuitState, CircuitBreakerOpenError };
/**
 * Database operation timeout in milliseconds
 * Default: 30 seconds (configurable via config)
 */
export declare const DB_OPERATION_TIMEOUT_MS = 30000;
/**
 * Database circuit breaker service name
 */
export declare const DATABASE_SERVICE_NAME = "database";
/**
 * Get the database circuit breaker instance
 */
export declare function getDatabaseCircuitBreaker(): CircuitBreaker;
/**
 * Check if the database circuit is currently open
 */
export declare function isDatabaseCircuitOpen(): Promise<boolean>;
/**
 * Get database circuit breaker status for monitoring
 */
export declare function getDatabaseCircuitStatus(): Promise<{
    name: string;
    state: CircuitState;
    failureCount: number;
    failureThreshold: number;
    resetTimeoutMs: number;
    timeUntilReset: number | null;
}>;
/**
 * Execute a database query with circuit breaker protection and timeout.
 *
 * This wrapper provides:
 * 1. Circuit breaker protection - fast fail when DB is unhealthy
 * 2. Statement timeout - prevents long-running queries
 * 3. Metrics recording - tracks success/failure rates
 *
 * @param fn - The database operation to execute
 * @param options - Optional configuration
 * @returns The result of the database operation
 * @throws CircuitBreakerOpenError when circuit is open
 * @throws StatementTimeoutError when query exceeds timeout
 *
 * @example
 * ```typescript
 * const users = await withDatabaseCircuitBreaker(
 *   async () => db.select().from(users).limit(100),
 *   { operationName: 'listUsers' }
 * );
 * ```
 */
export declare function withDatabaseCircuitBreaker<T>(fn: () => Promise<T>, options?: {
    operationName?: string;
    timeoutMs?: number;
}): Promise<T>;
/**
 * Execute a database operation with circuit breaker protection,
 * returning a result object instead of throwing on circuit open.
 *
 * This variant is useful when you want to handle circuit open gracefully
 * without try/catch, or when you want to use a fallback value.
 *
 * @param fn - The database operation to execute
 * @param options - Optional configuration
 * @returns Result object with success flag and result/error
 *
 * @example
 * ```typescript
 * const result = await withDatabaseCircuitBreakerResult(
 *   async () => db.select().from(cache).where(eq(cache.key, key)),
 *   { operationName: 'getCacheEntry' }
 * );
 *
 * if (result.circuitOpen) {
 *   // Use fallback - maybe return cached data or default
 *   return getFromLocalCache(key) ?? defaultValue;
 * }
 *
 * return result.success ? result.result : defaultValue;
 * ```
 */
export declare function withDatabaseCircuitBreakerResult<T>(fn: () => Promise<T>, options?: {
    operationName?: string;
    timeoutMs?: number;
}): Promise<{
    success: boolean;
    result?: T;
    error?: Error;
    circuitOpen: boolean;
}>;
/**
 * Execute a raw SQL query with circuit breaker protection.
 *
 * For cases where you need to execute raw SQL without Drizzle ORM.
 *
 * @param sql - SQL query string
 * @param params - Query parameters
 * @param options - Optional configuration
 * @returns Query result
 */
export declare function executeWithCircuitBreaker<T = unknown>(sql: string, params?: unknown[], options?: {
    operationName?: string;
    timeoutMs?: number;
}): Promise<T[]>;
/**
 * Force the database circuit breaker to open state.
 * Useful for manual intervention during maintenance or incidents.
 */
export declare function forceDatabaseCircuitOpen(): Promise<void>;
/**
 * Force the database circuit breaker to closed state.
 * Useful for manual recovery after maintenance.
 */
export declare function forceDatabaseCircuitClose(): Promise<void>;
/**
 * Reset the database circuit breaker.
 * Clears all state and returns to CLOSED state.
 */
export declare function resetDatabaseCircuit(): Promise<void>;
/**
 * Database health check with circuit breaker status.
 *
 * Returns comprehensive health information including:
 * - Database connectivity status
 * - Circuit breaker state
 * - Latency metrics
 */
export declare function checkDatabaseHealthWithCircuit(): Promise<{
    healthy: boolean;
    latencyMs?: number;
    error?: string;
    circuit: {
        state: CircuitState;
        failureCount: number;
        failureThreshold: number;
        timeUntilReset: number | null;
    };
}>;
//# sourceMappingURL=database-resilience.d.ts.map