import { Federation } from '@fedify/fedify';
import { H3Event, EventHandlerRequest, EventHandler, EventHandlerResponse, H3Error } from 'h3';

/**
 * A factory function that creates the context data that will be passed to the
 * `Federation` instance.
 * @typeParam TContextData The type of the context data that will be passed to
 *                         the `Federation` instance.
 * @param event The event that triggered the handler.
 * @param request The request that triggered the handler.
 * @returns The context data that will be passed to the `Federation` instance.
 *          This can be a promise that resolves to the context data.
 */
type ContextDataFactory<TContextData> = (event: H3Event<EventHandlerRequest>, request: Request) => Promise<TContextData> | TContextData;
/**
 * Integrates a `Federation` instance with an H3 handler.
 * @param federation
 * @param contextDataFactory
 * @returns
 */
declare function integrateFederation<TContextData>(federation: Federation<TContextData>, contextDataFactory: ContextDataFactory<TContextData>): EventHandler<EventHandlerRequest, EventHandlerResponse>;
/**
 * An error handler that responds with a 406 Not Acceptable if Fedify
 * responded with a 406 Not Acceptable and the actual handler responded with
 * a 404 Not Found.
 * @param error The error that occurred.
 * @param event The event that triggered the handler.
 */
declare function onError(error: H3Error<unknown>, event: H3Event<EventHandlerResponse>): Promise<void>;

export { type ContextDataFactory, integrateFederation, onError };
