import { SecurityModule, SecurityCheckResult, SecurityContext } from '@lock-dev/core';
export { registerModule } from '@lock-dev/core';
import { NextApiRequest, NextApiResponse } from 'next';
import { NextRequest } from 'next/server';

type NextApiHandler<T = any> = (req: NextApiRequest, res: NextApiResponse<T>) => Promise<void> | void;
type NextApiSecuredHandler<T = any> = (...modules: SecurityModule[]) => NextApiHandler<T>;
type NextResponseData = any;
type NextResponseInit = ResponseInit & {
    url?: string;
};
interface NextResponse<T = NextResponseData> extends Response {
    readonly headers: Headers;
    readonly ok: boolean;
    readonly redirected: boolean;
    readonly status: number;
    readonly statusText: string;
    readonly type: ResponseType;
    readonly url: string;
    readonly body: ReadableStream<Uint8Array> | null;
    readonly bodyUsed: boolean;
    clone(): NextResponse<T>;
    json(): Promise<T>;
    text(): Promise<string>;
}
type AppRouteHandler<T = NextResponseData> = (req: NextRequest) => Promise<Response> | Response;
type AppRouteSecuredHandler<T = NextResponseData> = (...modules: SecurityModule[]) => AppRouteHandler<T>;
type ServerActionFn = (...args: any[]) => Promise<any>;
type ServerActionSecuredFn<T extends ServerActionFn> = (...modules: SecurityModule[]) => T;
type EdgeMiddlewareHandler = (req: NextRequest) => Promise<Response>;
interface ResponseProxy {
    headersSent: boolean;
    writableEnded: boolean;
    statusCode: number;
    headers: Headers;
    status(code: number): ResponseProxy;
    setHeader(name: string, value: string): ResponseProxy;
    json(body: any): Response;
}
interface SecurityErrorMetadata {
    module: string;
    reason: string;
    type?: string;
    timestamp: string;
    severity?: string;
    details: Record<string, any>;
}
interface SecurityErrorResponse {
    error: string;
    blocked: boolean;
    meta: SecurityErrorMetadata;
    statusCode: number;
}

/**
 * Creates a response proxy object that simulates a response for App Router and Edge
 * @returns A response proxy object
 */
declare function createResponseProxy(): ResponseProxy;
/**
 * Extracts metadata from a security check result
 * @param context The security context
 * @param result The security check result
 * @returns Metadata about the security event
 */
declare function extractSecurityMetadata(result: SecurityCheckResult): SecurityErrorMetadata;
/**
 * Gets custom configuration for error responses from a module
 * @param context The security context
 * @param result The security check result
 * @returns Custom error configuration
 */
declare function getErrorConfig(context: SecurityContext, result: SecurityCheckResult): {
    statusCode: number;
    errorMessage: string;
};
/**
 * Creates an error response object for security failures
 * @param context The security context
 * @param result The security check result
 * @returns An error response data object
 */
declare function createErrorData(context: SecurityContext, result: SecurityCheckResult): SecurityErrorResponse;
/**
 * Creates a Response object for security failures
 * @param context The security context
 * @param result The security check result
 * @returns A Response object
 */
declare function createErrorResponse(context: SecurityContext, result: SecurityCheckResult): Response;
/**
 * Handles security failure for Pages API routes
 * @param context The security context
 * @param result The security check result
 * @param res The NextApiResponse object
 */
declare function handleSecurityFailure(context: SecurityContext, result: SecurityCheckResult, res: any): void;

/**
 * Creates a secured Pages API route handler
 *
 * @param handler The original Next.js API route handler
 * @returns A function that takes security modules and returns a secured handler
 */
declare function securePagesApi<T = any>(handler: NextApiHandler<T>): NextApiSecuredHandler<T>;

/**
 * Creates a secured App Router API route handler
 *
 * @param handler The original App Router handler
 * @returns A function that takes security modules and returns a secured handler
 */
declare function secureAppRoute<T = any>(handler: AppRouteHandler<T>): AppRouteSecuredHandler<T>;

/**
 * Creates a secured Server Action
 *
 * @param action The original Server Action function
 * @returns A function that takes security modules and returns a secured function
 */
declare function secureServerAction<T extends ServerActionFn>(action: T): ServerActionSecuredFn<T>;

/**
 * Creates a middleware configuration for Next.js Edge middleware
 *
 * @param modules Security modules to apply
 * @returns A middleware handler for Next.js Edge
 */
declare function createEdgeMiddleware(...modules: SecurityModule[]): EdgeMiddlewareHandler;

export { type AppRouteHandler, type AppRouteSecuredHandler, type EdgeMiddlewareHandler, type NextApiHandler, type NextApiSecuredHandler, type NextResponse, type NextResponseData, type NextResponseInit, type ResponseProxy, type SecurityErrorMetadata, type SecurityErrorResponse, type ServerActionFn, type ServerActionSecuredFn, createEdgeMiddleware, createErrorData, createErrorResponse, createResponseProxy, extractSecurityMetadata, getErrorConfig, handleSecurityFailure, secureAppRoute, securePagesApi, secureServerAction };
