import type { ConnectionInfo } from '@prisma/driver-adapter-utils';
import type { IsolationLevel } from '@prisma/driver-adapter-utils';
import * as neon from '@neondatabase/serverless';
import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
import type { SqlDriverAdapterFactory } from '@prisma/driver-adapter-utils';
import type { SqlQuery } from '@prisma/driver-adapter-utils';
import type { SqlQueryable } from '@prisma/driver-adapter-utils';
import type { SqlResultSet } from '@prisma/driver-adapter-utils';
import type { Transaction } from '@prisma/driver-adapter-utils';

declare type ARRAY_MODE_ENABLED = true;

/**
 * Base class for http client, ws client and ws transaction
 */
declare abstract class NeonQueryable implements SqlQueryable {
    readonly provider = "postgres";
    readonly adapterName: string;
    /**
     * Execute a query given as SQL, interpolating the given parameters.
     */
    queryRaw(query: SqlQuery): Promise<SqlResultSet>;
    /**
     * Execute a query given as SQL, interpolating the given parameters and
     * returning the number of affected rows.
     * Note: Queryable expects a u64, but napi.rs only supports u32.
     */
    executeRaw(query: SqlQuery): Promise<number>;
    /**
     * Run a query against the database, returning the result set.
     * Should the query fail due to a connection error, the connection is
     * marked as unhealthy.
     */
    abstract performIO(query: SqlQuery): Promise<PerformIOResult>;
}

/**
 * Base class for WS-based queryables: top-level client and transaction
 */
declare class NeonWsQueryable<ClientT extends neon.Pool | neon.PoolClient> extends NeonQueryable {
    protected client: ClientT;
    constructor(client: ClientT);
    performIO(query: SqlQuery): Promise<PerformIOResult>;
    protected onError(e: any): never;
}

declare type PerformIOResult = neon.QueryResult<any> | neon.FullQueryResults<ARRAY_MODE_ENABLED>;

export declare class PrismaNeon implements SqlDriverAdapterFactory {
    private readonly config;
    private options?;
    readonly provider = "postgres";
    readonly adapterName: string;
    constructor(config: neon.PoolConfig, options?: PrismaNeonOptions | undefined);
    connect(): Promise<PrismaNeonAdapter>;
}

declare class PrismaNeonAdapter extends NeonWsQueryable<neon.Pool> implements SqlDriverAdapter {
    private options?;
    private isRunning;
    constructor(pool: neon.Pool, options?: PrismaNeonOptions | undefined);
    executeScript(_script: string): Promise<void>;
    startTransaction(isolationLevel?: IsolationLevel): Promise<Transaction>;
    getConnectionInfo(): ConnectionInfo;
    dispose(): Promise<void>;
    underlyingDriver(): neon.Pool;
}

export declare class PrismaNeonHttp implements SqlDriverAdapterFactory {
    private readonly connectionString;
    private readonly options;
    readonly provider = "postgres";
    readonly adapterName: string;
    constructor(connectionString: string, options: neon.HTTPQueryOptions<boolean, boolean>);
    connect(): Promise<SqlDriverAdapter>;
}

declare type PrismaNeonOptions = {
    schema?: string;
    onPoolError?: (err: Error) => void;
    onConnectionError?: (err: Error) => void;
};

export { }
