/**
 * Thin HTTP transport wrapper around Node 18+'s built-in `fetch`. Centralises:
 *   - URL construction for the Bot API
 *   - x-www-form-urlencoded vs multipart/form-data body building
 *   - response parsing into Telegram's `{ ok, result, description, error_code }` envelope
 *   - error mapping into our error hierarchy
 */
import { type PreparedFile } from "./utils.js";
export interface RequestOptions {
    /** Scalar / structured fields. Sent as multipart when `formData` is present, else x-www-form-urlencoded. */
    form?: Record<string, unknown>;
    /** Multipart form data (file uploads) */
    formData?: Record<string, PreparedFile>;
    /** Per-call abort signal */
    signal?: AbortSignal;
    /** Per-call timeout in ms */
    timeoutMs?: number;
}
export interface TelegramApiOk<T> {
    ok: true;
    result: T;
}
export interface TelegramApiErr {
    ok: false;
    description?: string;
    error_code?: number;
    parameters?: {
        migrate_to_chat_id?: number;
        retry_after?: number;
    };
}
export type TelegramApiResponse<T> = TelegramApiOk<T> | TelegramApiErr;
export interface HttpClientOptions {
    baseApiUrl?: string;
    testEnvironment?: boolean;
    request?: {
        timeoutMs?: number;
        headers?: Record<string, string>;
        /**
         * On `429 Too Many Requests`, sleep for `retry_after` seconds (as
         * advertised by Telegram) and retry up to this many times. Set to `0`
         * to opt out. Defaults to `2`.
         */
        maxRetriesOn429?: number;
        /**
         * Custom `fetch` implementation, used in place of the global `fetch` for
         * every request from this client. The seam for per-instance proxying,
         * instrumentation, or test doubles - e.g. wrap undici's `fetch` bound to a
         * `ProxyAgent` dispatcher (no `setGlobalDispatcher`, so other clients in the
         * process are unaffected). Defaults to `globalThis.fetch`.
         */
        fetch?: typeof fetch;
        /**
         * Extra `fetch` init merged into every request - the place to pass options
         * the standard `RequestInit` does not type, most notably an undici
         * `dispatcher` for a per-instance proxy:
         *
         * ```ts
         * import { ProxyAgent } from "undici";
         * new TelegramBot(token, { request: { fetchOptions: { dispatcher: new ProxyAgent(proxyUrl) } } });
         * ```
         *
         * The client's own `method`/`body`/`headers`/`signal` always win over these,
         * so they cannot be overridden here. `dispatcher` is Node-only (undici).
         */
        fetchOptions?: RequestInit & {
            dispatcher?: unknown;
        };
    };
}
export declare class HttpClient {
    private readonly token;
    private readonly options;
    constructor(token: string, options?: HttpClientOptions);
    buildURL(method: string): string;
    request<T>(method: string, opts?: RequestOptions): Promise<T>;
    /**
     * Perform a single HTTP attempt: fire the request (honoring the per-call
     * timeout and abort signal) and parse Telegram's envelope. Throws
     * {@link FatalError} on a transport failure and {@link ParseError} on an
     * unparseable body; otherwise returns the HTTP status and parsed envelope
     * (ok or not) for the caller's retry/throw decision.
     */
    private _attempt;
}
//# sourceMappingURL=http.d.ts.map