import { AzionRuntimeRequest } from '../../../types/src/index.ts';
import { AzionRuntimeRequestMetadata } from '../../../types/src/index.ts';

/**
 * @function
 * @description The `mountMPA` function handles requests for Static Site Generation (SSG)
 * at the edge, directly within a serverless worker.
 * It processes the incoming request URL, constructs the appropriate asset path,
 * and fetches the corresponding response from the SSG.
 * @param {RequestURL} requestURL - The original URL from the event request.
 * @returns {Promise<Response>} A promise that resolves to the response from the SSG.
 * @example
 * // Handle a request for a homepage
 * // Input: mountMPA('https://example.com/');
 * // Output: fetch('file:///index.html');
 * @example
 * // Handle a request for an asset (CSS file)
 * // Input: mountMPA('https://example.com/styles/main.css');
 * // Output: fetch('file:///styles/main.css');
 * @example
 * // Handle a request for a specific route
 * // Input: mountMPA('https://example.com/about');
 * // Output: fetch('file:///about/index.html');
 */
export declare const mountMPA: mountMPAFunction;

/**
 * Function that mounts the SSG for a specific request.
 * @param requestURL - The original URL from the event request.
 * @returns A promise that resolves to the response from the SSG.
 */
declare type mountMPAFunction = (requestURL: RequestURL) => Promise<Response>;

/**
 * @function
 * @description The `mountSPA` function is designed to process requests to a Single Page Application (SPA)
 * that's being computed at the edge of a Content Delivery Network (CDN).
 *
 * This function determines if the incoming request is for a static
 * asset or a route within the application,
 * and mounts the appropriate request URL for fetching the required resource from the origin server.
 * @param {RequestURL} requestURL - The original URL from the incoming request.
 * @returns {Promise<Response>} A promise that resolves to the response from the fetched resource.
 * @example
 * // Handle a request for a homepage
 * // Input: mountSPA('https://example.com/');
 * // Output: fetch('file:///index.html');
 * @example
 * // Handle a request for an asset (CSS file)
 * // Input: mountSPA('https://example.com/styles/main.css');
 * // Output: fetch('file:///styles/main.css');
 * @example
 * // Handle a request for a specific route
 * // Input: mountSPA('https://example.com/about');
 * // Output: fetch('file:///index.html');
 */
export declare const mountSPA: MountSPAFunction;

/**
 * Function that mounts the SPA for a specific request.
 * @param requestURL - The original URL from the event request.
 * @returns A promise that resolves to the response from the SPA.
 */
declare type MountSPAFunction = (requestURL: RequestURL) => Promise<Response>;

/**
 * Function that parses and logs the details of an incoming request.
 * @param request - The incoming AzionRuntimeRequest object.
 * @returns A promise that resolves to the request details object.
 */
declare type ParsedRequest = {
    timestamp: string;
    method: string;
    url: {
        full: string;
        protocol: string;
        hostname: string;
        path: string;
        query: Record<string, string>;
    };
    headers: Record<string, string>;
    cookies: Record<string, string>;
    body: string | null;
    client: {
        ip: string;
        userAgent: string;
    };
    referer: string;
    origin: string;
    cacheControl: string;
    pragma: string;
    contentType: string;
    contentLength: string;
    acceptLanguage: string;
    acceptEncoding: string;
    priority: string;
    host: string;
    authorization: string;
    metadata: AzionRuntimeRequestMetadata;
};

/**
 * @function
 * @description The `parseRequest` function is designed to parse and log the details of an incoming request.
 * This function extracts key information such as headers, cookies, body, and client data from the incoming request,
 * providing a structured object with all these details for further processing or logging purposes.
 * @param {AzionRuntimeRequest} request - The incoming request object with metadata.
 * @returns {Promise<object>} A promise that resolves to an object containing detailed information about the request.
 * @example
 * // Parse a GET request
 * // Input: parseRequest(request);
 * // Output: {
 * //   timestamp: "2024-08-14T12:34:56.789Z",
 * //   metadata: {
 * //     geoip_asn: "12345",
 * //     geoip_city: "Sao Paulo",
 * //     geoip_city_continent_code: "SA",
 * //     geoip_city_country_code: "BR",
 * //     geoip_city_country_name: "Brazil",
 * //     // ... other metadata fields
 * //   },
 * //   method: "GET",
 * //   url: {
 * //     full: "https://example.com/",
 * //     protocol: "https:",
 * //     hostname: "example.com",
 * //     path: "/",
 * //     query: {}
 * //   },
 * //   headers: { ... },
 * //   cookies: { ... },
 * //   body: null,
 * //   client: {
 * //     ip: "123.45.67.89",
 * //     userAgent: "Mozilla/5.0 ..."
 * //   },
 * //   referer: "Unknown",
 * //   origin: "Unknown",
 * //   cacheControl: "Unknown",
 * //   pragma: "Unknown",
 * //   contentType: "Unknown",
 * //   contentLength: "Unknown",
 * //   acceptLanguage: "Unknown",
 * //   acceptEncoding: "Unknown",
 * //   priority: "Unknown",
 * //   host: "Unknown",
 * //   authorization: "Not Present"
 * // }
 */
export declare const parseRequest: ParseRequestFunction;

/**
 * Function that parses and logs the details of an incoming request.
 * @param request - The incoming AzionRuntimeRequest object.
 * @returns A promise that resolves to the ParsedRequest object.
 */
declare type ParseRequestFunction = (request: AzionRuntimeRequest) => Promise<ParsedRequest>;

/**
 * Represents the request URL for the SSG or SPA.
 */
declare type RequestURL = string;

export { }
