import { PgDatabase, PgQueryResultHKT, PgTransaction, PgTransactionConfig } from 'drizzle-orm/pg-core';
import { ExtractTablesWithRelations } from 'drizzle-orm';

/** The host's drizzle schema (pgTables + relations). db core defines none — it is generic over this. */
type Schema = Record<string, unknown>;
/** Query-capable handle WITHOUT interactive transactions. What `./neon-http` returns. */
type Database<S extends Schema = Record<string, never>> = Omit<PgDatabase<PgQueryResultHKT, S, ExtractTablesWithRelations<S>>, 'transaction'>;
/** The handle inside a `.transaction()` callback. */
type Transaction<S extends Schema = Record<string, never>> = PgTransaction<PgQueryResultHKT, S, ExtractTablesWithRelations<S>>;
/** Adds interactive transactions back. What `./neon-serverless`, `./postgres-js`, `./pglite` return. */
type TransactionalDatabase<S extends Schema = Record<string, never>> = Database<S> & {
    transaction<T>(fn: (tx: Transaction<S>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
};
/** The workhorse: ANY query-capable handle — in or out of a tx. EVERY query helper accepts this. */
type Querier<S extends Schema = Record<string, never>> = Database<S> | Transaction<S>;

export type { Database, Querier, Schema, Transaction, TransactionalDatabase };
