import * as _btst_stack_plugins_api from '@btst/stack/plugins/api';
import * as better_call from 'better-call';
import { S as SerializedForm, b as SerializedFormSubmissionWithData, F as Form, d as FormSubmission, a as SerializedFormSubmission, e as FormSubmissionWithForm, f as FormBuilderBackendConfig } from './stack.BozPgbrZ.js';
import { z } from 'zod';
import { Adapter } from '@btst/db';
import { QueryClient } from '@tanstack/react-query';

/**
 * Serialize a Form for SSR/SSG use (convert dates to strings).
 */
declare function serializeForm(form: Form): SerializedForm;
/**
 * Serialize a FormSubmission for SSR/SSG use (convert dates to strings).
 */
declare function serializeFormSubmission(submission: FormSubmission): SerializedFormSubmission;
/**
 * Serialize a FormSubmission with parsed data and joined Form.
 * If `submission.data` is corrupted JSON, `parsedData` is set to `null` rather
 * than throwing, so one bad row cannot crash the entire list or SSG build.
 */
declare function serializeFormSubmissionWithData(submission: FormSubmissionWithForm): SerializedFormSubmissionWithData;
/**
 * Retrieve all forms with optional status filter and pagination.
 * Pure DB function — no hooks, no HTTP context. Safe for SSG and server-side use.
 *
 * @remarks **Security:** Authorization hooks (e.g. `onBeforeListForms`) are NOT
 * called. The caller is responsible for any access-control checks before
 * invoking this function.
 *
 * @param adapter - The database adapter
 * @param params - Optional filter/pagination parameters
 */
declare function getAllForms(adapter: Adapter, params?: {
    status?: string;
    limit?: number;
    offset?: number;
}): Promise<{
    items: SerializedForm[];
    total: number;
    limit?: number;
    offset?: number;
}>;
/**
 * Retrieve a single form by its ID (UUID).
 * Returns null if the form is not found.
 * Pure DB function — no hooks, no HTTP context. Safe for SSG and server-side use.
 *
 * @remarks **Security:** Authorization hooks are NOT called. The caller is
 * responsible for any access-control checks before invoking this function.
 *
 * @param adapter - The database adapter
 * @param id - The form UUID
 */
declare function getFormById(adapter: Adapter, id: string): Promise<SerializedForm | null>;
/**
 * Retrieve a single form by its slug.
 * Returns null if the form is not found.
 * Pure DB function — no hooks, no HTTP context. Safe for SSG and server-side use.
 *
 * @remarks **Security:** Authorization hooks are NOT called. The caller is
 * responsible for any access-control checks before invoking this function.
 *
 * @param adapter - The database adapter
 * @param slug - The form slug
 */
declare function getFormBySlug(adapter: Adapter, slug: string): Promise<SerializedForm | null>;
/**
 * Retrieve submissions for a form by form ID, with optional pagination.
 * Returns an empty result if the form does not exist.
 * Pure DB function — no hooks, no HTTP context. Safe for server-side use.
 *
 * @remarks **Security:** Authorization hooks are NOT called. The caller is
 * responsible for any access-control checks before invoking this function.
 *
 * @param adapter - The database adapter
 * @param formId - The form ID
 * @param params - Optional pagination parameters
 */
declare function getFormSubmissions(adapter: Adapter, formId: string, params?: {
    limit?: number;
    offset?: number;
}): Promise<{
    items: SerializedFormSubmissionWithData[];
    total: number;
    limit?: number;
    offset?: number;
}>;

/**
 * Route keys for the Form Builder plugin — matches the keys returned by
 * `stackClient.router.getRoute(path).routeKey`.
 */
type FormBuilderRouteKey = "formList" | "newForm" | "editForm" | "submissions";
interface FormBuilderPrefetchForRoute {
    (key: "formList" | "newForm", qc: QueryClient): Promise<void>;
    (key: "editForm" | "submissions", qc: QueryClient, params: {
        id: string;
    }): Promise<void>;
}
/**
 * Form Builder backend plugin
 * Provides API endpoints for managing forms and form submissions
 *
 * @param config - Configuration with optional hooks
 */
declare const formBuilderBackendPlugin: (config?: FormBuilderBackendConfig) => _btst_stack_plugins_api.BackendPlugin<{
    listForms: better_call.StrictEndpoint<"/forms", {
        method: "GET";
        query: z.ZodObject<{
            status: z.ZodOptional<z.ZodEnum<{
                active: "active";
                inactive: "inactive";
                archived: "archived";
            }>>;
            limit: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
            offset: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
        }, z.core.$strip>;
    }, {
        items: SerializedForm[];
        total: number;
        limit?: number;
        offset?: number;
    }>;
    getFormBySlug: better_call.StrictEndpoint<"/forms/:slug", {
        method: "GET";
        params: z.ZodObject<{
            slug: z.ZodString;
        }, z.core.$strip>;
    }, SerializedForm>;
    getFormById: better_call.StrictEndpoint<"/forms/id/:id", {
        method: "GET";
        params: z.ZodObject<{
            id: z.ZodString;
        }, z.core.$strip>;
    }, SerializedForm>;
    createForm: better_call.StrictEndpoint<"/forms", {
        method: "POST";
        body: z.ZodObject<{
            name: z.ZodString;
            slug: z.ZodString;
            description: z.ZodOptional<z.ZodString>;
            schema: z.ZodString;
            successMessage: z.ZodOptional<z.ZodString>;
            redirectUrl: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
            status: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
                active: "active";
                inactive: "inactive";
                archived: "archived";
            }>>>;
        }, z.core.$strip>;
    }, SerializedForm>;
    updateForm: better_call.StrictEndpoint<"/forms/:id", {
        method: "PUT";
        params: z.ZodObject<{
            id: z.ZodString;
        }, z.core.$strip>;
        body: z.ZodObject<{
            name: z.ZodOptional<z.ZodString>;
            slug: z.ZodOptional<z.ZodString>;
            description: z.ZodOptional<z.ZodString>;
            schema: z.ZodOptional<z.ZodString>;
            successMessage: z.ZodOptional<z.ZodString>;
            redirectUrl: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
            status: z.ZodOptional<z.ZodEnum<{
                active: "active";
                inactive: "inactive";
                archived: "archived";
            }>>;
        }, z.core.$strip>;
    }, SerializedForm>;
    deleteForm: better_call.StrictEndpoint<"/forms/:id", {
        method: "DELETE";
        params: z.ZodObject<{
            id: z.ZodString;
        }, z.core.$strip>;
    }, {
        success: boolean;
    }>;
    submitForm: better_call.StrictEndpoint<"/forms/:slug/submit", {
        method: "POST";
        params: z.ZodObject<{
            slug: z.ZodString;
        }, z.core.$strip>;
        body: z.ZodObject<{
            data: z.ZodObject<{}, z.core.$loose>;
        }, z.core.$strip>;
    }, {
        form: {
            successMessage: string | undefined;
            redirectUrl: string | undefined;
        };
        submittedAt: string;
        id: string;
        data: string;
        formId: string;
        submittedBy?: string | undefined;
        ipAddress?: string | undefined;
        userAgent?: string | undefined;
    }>;
    listSubmissions: better_call.StrictEndpoint<"/forms/:formId/submissions", {
        method: "GET";
        params: z.ZodObject<{
            formId: z.ZodString;
        }, z.core.$strip>;
        query: z.ZodObject<{
            limit: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
            offset: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
        }, z.core.$strip>;
    }, {
        items: SerializedFormSubmissionWithData[];
        total: number;
        limit?: number;
        offset?: number;
    }>;
    getSubmission: better_call.StrictEndpoint<"/forms/:formId/submissions/:subId", {
        method: "GET";
        params: z.ZodObject<{
            formId: z.ZodString;
            subId: z.ZodString;
        }, z.core.$strip>;
    }, SerializedFormSubmissionWithData<Record<string, unknown>>>;
    deleteSubmission: better_call.StrictEndpoint<"/forms/:formId/submissions/:subId", {
        method: "DELETE";
        params: z.ZodObject<{
            formId: z.ZodString;
            subId: z.ZodString;
        }, z.core.$strip>;
    }, {
        success: boolean;
    }>;
}, {
    getAllForms: (params?: Parameters<typeof getAllForms>[1]) => Promise<{
        items: SerializedForm[];
        total: number;
        limit?: number;
        offset?: number;
    }>;
    getFormById: (id: string) => Promise<SerializedForm | null>;
    getFormBySlug: (slug: string) => Promise<SerializedForm | null>;
    getFormSubmissions: (formId: string, params?: Parameters<typeof getFormSubmissions>[2]) => Promise<{
        items: SerializedFormSubmissionWithData[];
        total: number;
        limit?: number;
        offset?: number;
    }>;
    prefetchForRoute: FormBuilderPrefetchForRoute;
}>;
type FormBuilderApiRouter = ReturnType<ReturnType<typeof formBuilderBackendPlugin>["routes"]>;

/**
 * Internal query key constants for the Form Builder plugin.
 * Shared between query-keys.ts (HTTP path) and prefetchForRoute (DB path)
 * to prevent key drift between SSR loaders and SSG prefetching.
 */
interface FormsListDiscriminator {
    status?: "active" | "inactive" | "archived";
    limit: number;
    offset: number;
}
interface SubmissionsListDiscriminator {
    formId: string;
    limit: number;
    offset: number;
}
/** Full query key builders — use these with queryClient.setQueryData() */
declare const FORM_QUERY_KEYS: {
    /**
     * Key for forms.list(params) query.
     * Full key: ["forms", "list", "list", { status, limit, offset }]
     */
    formsList: (params?: {
        status?: "active" | "inactive" | "archived";
        limit?: number;
        offset?: number;
    }) => readonly ["forms", "list", "list", FormsListDiscriminator];
    /**
     * Key for forms.byId(id) query.
     * Full key: ["forms", "byId", "byId", id]
     */
    formById: (id: string) => readonly ["forms", "byId", "byId", string];
    /**
     * Key for formSubmissions.list(params) query.
     * Full key: ["formSubmissions", "list", { formId, limit, offset }]
     */
    submissionsList: (params: {
        formId: string;
        limit?: number;
        offset?: number;
    }) => readonly ["formSubmissions", "list", SubmissionsListDiscriminator];
};

export { getFormById as c, getFormBySlug as d, getFormSubmissions as e, formBuilderBackendPlugin as f, getAllForms as g, serializeFormSubmission as h, serializeFormSubmissionWithData as i, FORM_QUERY_KEYS as j, serializeForm as s };
export type { FormBuilderApiRouter as F, SubmissionsListDiscriminator as S, FormsListDiscriminator as a, FormBuilderRouteKey as b };
