import type { FileConnectionBase } from './index.ts';
import type { Nxtpression } from '../../../../common/nxtpression.ts';
export interface FileConnectionHttpRecord extends FileConnectionBase {
    protocol?: "http";
    secure?: boolean;
    authType?: "oauth2" | "none";
    oauth2?: {
        client?: {
            id?: string;
            secret?: string;
            secretParamName?: string;
            idParamName?: string;
        };
        auth?: {
            tokenHost?: string;
            tokenPath?: string;
            refreshPath?: string;
            revokePath?: string;
        };
        /**
         * Default (static) parameters to be sent with the token request.
         * Username and password should not be stored here, but rather provided
         * by the hub through the `connect` rpc method.
         */
        tokenParams?: {
            [key: string]: string;
        };
        grantType?: "password";
        token?: {
            accessToken: string;
            refreshToken: string | null;
            expiresAt: number | null;
            idToken?: string;
        };
        error?: string;
    };
    actions?: HttpConnectionActions;
}
export interface HttpConnectionActions {
    ping?: FileConnectionHttpAction;
    head?: FileConnectionHttpAction<{
        filepath: string;
    }, FileConnectionHeadResponse | undefined>;
    list?: FileConnectionHttpAction<{
        dirpath?: string;
    }, FileConnectionListResponseItem[]>;
    get?: FileConnectionHttpAction<{
        id: string;
        offset?: number;
    }>;
    put?: FileConnectionHttpAction<{
        filepath: string;
        stream: unknown;
    }>;
    del?: FileConnectionHttpAction<{
        id: string;
    }>;
}
export interface FileConnectionHttpAction<RequestTemplateContext extends Record<string, unknown> = Record<string, unknown>, ResponseHandlerResult = undefined> {
    request?: {
        [Key in keyof HttpConnectionRequest]: Nxtpression<HttpConnectionRequest[Key], RequestTemplateContext & {
            connection: FileConnectionHttpRecord;
        }>;
    };
    response?: HttpConnectionResponseHandler<ResponseHandlerResult>;
}
export interface HttpConnectionRequest {
    origin?: string;
    path?: string;
    method?: string;
    params?: {
        [key: string]: string | undefined;
    };
    form?: {
        [name: string]: {
            value: unknown;
            filename: string | undefined;
        };
    };
    headers?: {
        [key: string]: string | undefined;
    };
    throwOnError?: boolean;
}
export declare const isHttpConnectionRequest: (input: unknown) => input is HttpConnectionRequest;
/**
 * Describes how to handle the response from an HTTP action
 */
export interface HttpConnectionResponseHandler<ResOutput = undefined> {
    responseFormat?: "text" | "json" | "stream";
    /** Resolve to an error message to indicate failure */
    error?: Nxtpression<string | null | undefined, {
        connection: FileConnectionHttpRecord;
        headers: Record<string, string | string[] | undefined>;
        statusCode: number;
    }>;
    /** Resolve to the desired output. Input will be parsed according to responseFormat. */
    transform?: Nxtpression<ResOutput, {
        connection: FileConnectionHttpRecord;
        /** Body parsed as JSON if responseFormat is 'json' */
        json?: unknown;
        /** Body as text if responseFormat is 'text' */
        text?: string;
        /** Response headers */
        headers: Record<string, string | string[] | undefined>;
        /** Response status code */
        statusCode: number;
    }>;
}
export interface FileConnectionHttpPasswordAuth {
    username: string;
    password: string;
    scope?: string[];
    resource?: string | string[];
}
export declare const isFileConnectionHttpPasswordAuth: (input: unknown) => input is FileConnectionHttpPasswordAuth;
interface FileConnectionHeadResponse {
    size?: number;
    hash?: string;
}
export declare const isFileConnectionHeadResponse: (input: unknown) => input is FileConnectionHeadResponse;
export interface FileConnectionListResponseItem {
    name: string;
    isDir: boolean;
    size: number;
    date?: string;
    path: string;
}
export declare const isFileConnectionListResponseItem: (input: unknown) => input is FileConnectionListResponseItem;
export {};
