import { AgentsManageDatabaseClient } from "@inkeep/agents-core";
import { Context, Next } from "hono";
import { Pool } from "pg";

//#region src/middleware/branchScopedDb.d.ts
declare function isProjectDeleteOperation(path: string, method: string): boolean;
/**
 * Get the underlying connection pool from a Drizzle database client
 */
declare function getPoolFromClient(client: AgentsManageDatabaseClient): Pool | null;
/**
 * Middleware that provides branch-scoped database connections
 *
 * Flow:
 * 1. Get a dedicated connection from the pool
 * 2. If ref is specified, checkout that branch/tag/commit on this connection
 * 3. Create a Drizzle client wrapping this specific connection
 * 4. Inject into context as 'db' (request-scoped database client)
 * 5. Execute the route handler
 * 6. For write operations on branches: auto-commit changes
 * 7. Always cleanup: checkout main and release connection
 *
 * This ensures:
 * - All operations in a request use the same connection (correct)
 * - Only one checkout per request (performant)
 * - Automatic commits for successful writes on branches
 * - Proper connection cleanup
 */
declare const branchScopedDbMiddleware: (c: Context, next: Next) => Promise<void>;
//#endregion
export { branchScopedDbMiddleware, getPoolFromClient, isProjectDeleteOperation };