import * as drizzle_orm_neon_http from 'drizzle-orm/neon-http';

declare class QueryPromise<T = any> implements Promise<T> {
    private executeFn;
    readonly [Symbol.toStringTag]: string;
    queryData: ParameterizedQuery;
    opts?: any;
    constructor(executeFn: (query: string, params: any[]) => Promise<T>, queryObj: ParameterizedQuery, opts?: any);
    then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
    catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<T | TResult>;
    finally(onfinally?: (() => void) | null | undefined): Promise<T>;
    [Symbol.iterator](): Iterator<T>;
}

declare enum PgTypeId {
    BOOL = 16,
    BYTEA = 17,
    CHAR = 18,
    INT8 = 20,
    INT2 = 21,
    INT4 = 23,
    REGPROC = 24,
    TEXT = 25,
    OID = 26,
    TID = 27,
    XID = 28,
    CID = 29,
    JSON = 114,
    XML = 142,
    PG_NODE_TREE = 194,
    JSONB = 3802,
    FLOAT4 = 700,
    FLOAT8 = 701,
    ABSTIME = 702,
    RELTIME = 703,
    TINTERVAL = 704,
    CIRCLE = 718,
    MONEY = 790,
    MACADDR = 829,
    INET = 869,
    CIDR = 650,
    MACADDR8 = 774,
    ACLITEM = 1033,
    BPCHAR = 1042,
    VARCHAR = 1043,
    DATE = 1082,
    TIME = 1083,
    TIMESTAMP = 1114,
    TIMESTAMPTZ = 1184,
    INTERVAL = 1186,
    TIMETZ = 1266,
    BIT = 1560,
    VARBIT = 1562,
    NUMERIC = 1700,
    REFCURSOR = 1790,
    REGPROCEDURE = 2202,
    REGOPER = 2203,
    REGOPERATOR = 2204,
    REGCLASS = 2205,
    REGTYPE = 2206,
    UUID = 2950,
    TXID_SNAPSHOT = 2970,
    PG_LSN = 3220,
    PG_NDISTINCT = 3361,
    PG_DEPENDENCIES = 3402,
    TSVECTOR = 3614,
    TSQUERY = 3615,
    GTSVECTOR = 3642,
    REGCONFIG = 3734,
    REGDICTIONARY = 3769,
    JSONPATH = 4072,
    REGNAMESPACE = 4089,
    REGROLE = 4096,
    BOOL_ARRAY = 1000,// Boolean Array -> 16 + 1000 - 16 = 1000
    BYTEA_ARRAY = 1001,// Bytea Array -> 17 + 1000 - 16 = 1001
    CHAR_ARRAY = 1002,// Char Array -> 18 + 1000 - 16 = 1002
    INT8_ARRAY = 1016,// BigInt Array -> 20 + 1000 - 4 = 1016
    INT2_ARRAY = 1005,// SmallInt Array -> 21 + 1000 - 16 = 1005
    INT4_ARRAY = 1007,// Integer Array -> 23 + 1000 - 16 = 1007
    TEXT_ARRAY = 1009,// Text Array -> 25 + 1000 - 16 = 1009
    JSON_ARRAY = 199,// JSON Array -> 114 + 1000 - 915 = 199
    JSONB_ARRAY = 3807,// JSONB Array -> 3802 + 5 = 3807
    FLOAT4_ARRAY = 1021,// Float4 Array -> 700 + 1000 - 679 = 1021
    FLOAT8_ARRAY = 1022,// Float8 Array -> 701 + 1000 - 679 = 1022
    NUMERIC_ARRAY = 1231,// Numeric Array -> 1700 + 1000 - 1469 = 1231
    DATE_ARRAY = 1182,// Date Array -> 1082 + 100 = 1182
    TIMESTAMP_ARRAY = 1115,// Timestamp Array -> 1114 + 1 = 1115
    TIMESTAMPTZ_ARRAY = 1185,// Timestamptz Array -> 1184 + 1 = 1185
    UUID_ARRAY = 2951,// UUID Array -> 2950 + 1 = 2951
    VARCHAR_ARRAY = 1015
}
declare class TypeParser {
    private parsers;
    constructor(customTypes?: Record<number, (value: string) => any>);
    private initializeDefaultParsers;
    private setupArrayTypeParsers;
    setTypeParser(typeId: number, parseFn: (value: string) => any): void;
    getTypeParser(typeId: number): (value: string) => any;
}

interface PgQueryResult {
    command: string;
    fields: PgField[];
    rowCount: number;
    rows: any[];
    rowAsArray: boolean;
    _parsers?: any[];
    _types?: TypeParser;
}
interface PgField {
    name: string;
    tableID: number;
    columnID: number;
    dataTypeID: number;
    dataTypeSize: number;
    dataTypeModifier: number;
    format: string;
}
interface ParameterizedQuery {
    query: string;
    params: any[];
}
type SQLTemplateTag = (strings: TemplateStringsArray, ...values: any[]) => QueryPromise<PgQueryResult>;
interface TransactionQuery {
    text: string;
    values: unknown[];
    captureGeneratedId?: boolean;
}
interface ClientOptions {
    proxyUrl: string;
    authToken?: string;
    fetch?: typeof globalThis.fetch;
    arrayMode?: boolean;
    fullResults?: boolean;
    typeParser?: TypeParser | Record<number, (value: string) => any>;
    sessionId?: string;
    logger?: LoggerOptions;
}
declare enum LogLevel {
    Debug = 1,
    Info = 2,
    Warn = 3,
    Error = 4,
    None = 5
}
interface LoggerOptions {
    level?: LogLevel;
    logFn?: (level: LogLevel, message: string, data?: any) => void;
}

declare class UnsafeRawSql {
    sql: string;
    constructor(sql: string);
}

declare class PgError extends Error {
    name: "PgError";
    severity?: string;
    code?: string;
    detail?: string;
    hint?: string;
    position?: string;
    internalPosition?: string;
    internalQuery?: string;
    where?: string;
    schema?: string;
    table?: string;
    column?: string;
    dataType?: string;
    constraint?: string;
    file?: string;
    line?: string;
    routine?: string;
    sourceError?: Error;
    constructor(message: string);
}

declare function createPgHttpClient({ proxyUrl, authToken, fetch: customFetch, arrayMode, fullResults, typeParser: customTypeParser, sessionId, logger: loggerOptions }: ClientOptions): {
    execute: (queryText: string, params?: any[]) => Promise<PgQueryResult>;
    query: (queryText: string, params?: any[], options?: {
        arrayMode?: boolean;
        fullResults?: boolean;
    }) => Promise<PgQueryResult>;
    sql: (strings: TemplateStringsArray, ...values: unknown[]) => QueryPromise<PgQueryResult>;
    unsafe: (rawSql: string) => UnsafeRawSql;
    transaction: (queries: (TransactionQuery | QueryPromise<PgQueryResult>)[], options?: {
        isolationLevel?: "ReadUncommitted" | "ReadCommitted" | "RepeatableRead" | "Serializable";
        readOnly?: boolean;
        deferrable?: boolean;
        arrayMode?: boolean;
        fullResults?: boolean;
    }) => Promise<any[]>;
    typeParser: TypeParser;
};

/**
 * Creates a Drizzle client connecting to PostgreSQL via HTTP proxy.
 * This client is compatible with both drizzle-orm and Auth.js.
 *
 * @param options Configuration options
 * @returns Drizzle ORM instance for your database
 */
declare function drizzle<TSchema extends Record<string, unknown>>(options: {
    proxyUrl: string;
    authToken?: string;
    schema: TSchema;
    fetch?: typeof globalThis.fetch;
    arrayMode?: boolean;
    fullResults?: boolean;
    typeParser?: TypeParser | Record<number, (value: string) => any>;
    logger?: LoggerOptions;
}): drizzle_orm_neon_http.NeonHttpDatabase<TSchema> & {
    $client: any;
};

/**
 * Common types used throughout the package
 */
/**
 * Options for creating a PostgreSQL HTTP client
 */
interface PgHttpClientOptions {
    /**
     * URL of the PostgreSQL HTTP proxy server
     */
    proxyUrl: string;
    /**
     * Optional authentication token for the proxy server
     */
    authToken?: string;
    /**
     * Optional fetch implementation (uses globalThis.fetch by default)
     */
    fetch?: typeof globalThis.fetch;
}
/**
 * Options for creating a Drizzle ORM client
 */
interface DrizzleClientOptions<TSchema extends Record<string, unknown>> extends PgHttpClientOptions {
    /**
     * Drizzle schema definition
     */
    schema: TSchema;
}
/**
 * SQL query parameters
 */
interface QueryParams {
    text: string;
    values: unknown[];
}
/**
 * Result of a SQL template literal
 */
interface SqlQueryResult {
    query: string;
    params: unknown[];
    execute: () => Promise<any[]>;
}
/**
 * PostgreSQL HTTP client interface
 */
interface PgHttpClient {
    execute: (query: string, params?: unknown[]) => Promise<any[]>;
    sql: (strings: TemplateStringsArray, ...values: unknown[]) => SqlQueryResult;
    transaction: (queries: QueryParams[]) => Promise<any[]>;
    query: (query: string, params?: unknown[]) => Promise<any[]>;
}

export { type ClientOptions, type DrizzleClientOptions, LogLevel, type ParameterizedQuery, PgError, type PgField, type PgHttpClient, type PgHttpClientOptions, type PgQueryResult, PgTypeId, type QueryParams, type SQLTemplateTag, type SqlQueryResult, TypeParser, UnsafeRawSql, createPgHttpClient, drizzle };
