import { Logger, type ObjectTS, type ValidatorTypeResolver } from "@intuitionrobotics/ts-common";
import { Stream } from "stream";
import { type ServerApi_Middleware } from "./HttpServer.js";
import { type IncomingHttpHeaders } from "http";
import { type ApiTypeBinder, HttpMethod, type QueryParams } from "../../../shared/types.js";
import { ApiException } from "../../exceptions.js";
import { type ExpressRequest, type ExpressResponse } from "../../utils/types.js";
export type HttpRequestData = {
    originalUrl: string;
    headers: IncomingHttpHeaders;
    url: string;
    query: any;
    body: any;
    method: HttpMethod;
};
export declare abstract class ServerApi<Binder extends ApiTypeBinder<string, R, B, P>, R = Binder["response"], B = Binder["body"], P extends QueryParams = Binder["queryParams"]> extends Logger {
    static isDebug: boolean;
    private printResponse;
    readonly headersToLog: string[];
    readonly method: HttpMethod;
    readonly relativePath: string;
    private middlewares?;
    private bodyValidator?;
    private queryValidator?;
    private scopes;
    protected constructor(method: HttpMethod, relativePath?: string, tag?: string);
    private _handler?;
    get handler(): (req: ExpressRequest, res: ExpressResponse, next?: (err?: any) => void) => Promise<void>;
    shouldPrintResponse(): boolean;
    setMiddlewares(...middlewares: ServerApi_Middleware[]): this;
    addMiddlewares(...middlewares: ServerApi_Middleware[]): this;
    setScopes(...scopes: string[]): this;
    getScopes(): string[];
    addHeaderToLog(...headersToLog: string[]): void;
    setBodyValidator(bodyValidator: ValidatorTypeResolver<B>): void;
    setQueryValidator(queryValidator: ValidatorTypeResolver<P>): void;
    asProxy(): ServerApi<Binder>;
    dontPrintResponse(): void;
    setMaxResponsePrintSize(printResponseMaxSizeBytes: number): void;
    assertProperty: <T extends object, K extends keyof T = keyof T>(instance: T, key: K | K[], statusCode?: number, check?: string | ((propValue: T[K]) => void)) => void;
    call(req: ExpressRequest, res: ExpressResponse): Promise<void>;
    private applyMiddlewares;
    protected abstract process(request: ExpressRequest, response: ApiResponse, queryParams: P, body: B, context: ObjectTS): Promise<R>;
}
export declare class ServerApi_Proxy<Binder extends ApiTypeBinder<string, R, B, P>, R = Binder["response"], B = Binder["body"], P extends QueryParams = Binder["queryParams"]> extends ServerApi<Binder> {
    private readonly api;
    constructor(api: ServerApi<any>);
    protected process(request: ExpressRequest, response: ApiResponse, queryParams: P, body: B, context: ObjectTS): Promise<R>;
}
export declare class ServerApi_Redirect extends ServerApi<any> {
    private readonly responseCode;
    private readonly redirectUrl;
    constructor(apiName: string, responseCode: number, redirectUrl: string);
    protected process(request: ExpressRequest, response: ApiResponse, queryParams: QueryParams, _body: any): Promise<void>;
}
export declare class ApiResponse {
    private api;
    private readonly res;
    private consumed;
    constructor(api: ServerApi<any>, res: ExpressResponse);
    isConsumed(): boolean;
    private consume;
    stream(responseCode: number, stream: Stream, headers?: any): void;
    private printHeaders;
    private printResponse;
    code(responseCode: number, headers?: any): void;
    text(responseCode: number, response?: string, _headers?: any): void;
    html(responseCode: number, response?: string, _headers?: any): void;
    json(responseCode: number, response?: object | string, _headers?: any): void;
    private _json;
    end(responseCode: number, response?: object | string, headers?: any): void;
    setHeaders(headers: any): void;
    setHeader(headerKey: string, value: string | string[]): void;
    getHeader(headerKey: string): string | undefined;
    redirect(responseCode: number, url: string): void;
    exception(exception: ApiException, headers?: any): void;
    serverError(error: Error & {
        cause?: Error;
    }, headers?: any): void;
}
//# sourceMappingURL=server-api.d.ts.map