import * as _btst_stack_plugins_api from '@btst/stack/plugins/api';
import { a as SerializedContentItemWithType, S as SerializedContentType, b as ContentType, c as ContentItem, d as SerializedContentItem, e as ContentItemWithType, f as CMSBackendConfig, I as InverseRelation } from './stack.B8QD11QU.js';
import * as better_call from 'better-call';
import { z } from 'zod';
import { Adapter } from '@btst/db';
import { QueryClient } from '@tanstack/react-query';

/**
 * Serialize a ContentType for SSR/SSG use (convert dates to strings).
 * Applies lazy migration for legacy schemas (version 1 → 2).
 */
declare function serializeContentType(ct: ContentType): SerializedContentType;
/**
 * Serialize a ContentItem for SSR/SSG use (convert dates to strings).
 */
declare function serializeContentItem(item: ContentItem): SerializedContentItem;
/**
 * Serialize a ContentItem with parsed data and joined ContentType.
 * Throws a SyntaxError if `item.data` is not valid JSON, so corrupted rows
 * produce a visible, debuggable error rather than silently returning null.
 */
declare function serializeContentItemWithType(item: ContentItemWithType): SerializedContentItemWithType;
/**
 * Retrieve all content types.
 * 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
 */
declare function getAllContentTypes(adapter: Adapter): Promise<SerializedContentType[]>;
/**
 * Retrieve all content items for a given content type, with optional pagination.
 * Pure DB function — no hooks, no HTTP context. Safe for SSG and server-side use.
 *
 * @remarks **Security:** Authorization hooks (e.g. `onBeforeListItems`) are NOT
 * called. The caller is responsible for any access-control checks before
 * invoking this function.
 *
 * @param adapter - The database adapter
 * @param contentTypeSlug - The slug of the content type to query
 * @param params - Optional filter/pagination parameters
 */
declare function getAllContentItems(adapter: Adapter, contentTypeSlug: string, params?: {
    slug?: string;
    limit?: number;
    offset?: number;
}): Promise<{
    items: SerializedContentItemWithType[];
    total: number;
    limit?: number;
    offset?: number;
}>;
/**
 * Retrieve a single content item by its ID.
 * Returns null if the item 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 content item ID (UUID)
 */
declare function getContentItemById(adapter: Adapter, id: string): Promise<SerializedContentItemWithType | null>;
/**
 * Retrieve a single content item by its slug within a content type.
 * Returns null if the content type or item 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 contentTypeSlug - The slug of the content type
 * @param slug - The slug of the content item
 */
declare function getContentItemBySlug(adapter: Adapter, contentTypeSlug: string, slug: string): Promise<SerializedContentItemWithType | null>;

/**
 * Input for creating a new CMS content item.
 */
interface CreateCMSContentItemInput {
    /** URL-safe slug for the item */
    slug: string;
    /** Arbitrary data payload — should match the content type schema */
    data: Record<string, unknown>;
}
/**
 * Create a new content item for a content type (looked up by slug).
 *
 * Bypasses Zod schema validation and relation processing — the caller is
 * responsible for providing valid, relation-free data. For relation fields or
 * schema validation, use the HTTP endpoint instead.
 *
 * Throws if the content type is not found or the slug is already taken within
 * that content type.
 *
 * @remarks **Security:** No authorization hooks (`onBeforeCreate`, `onAfterCreate`)
 * are called. The caller is responsible for any access-control checks before
 * invoking this function.
 *
 * @param adapter - The database adapter
 * @param contentTypeSlug - Slug of the target content type
 * @param input - Item slug and data payload
 */
declare function createCMSContentItem(adapter: Adapter, contentTypeSlug: string, input: CreateCMSContentItemInput): Promise<SerializedContentItem>;

/**
 * Route keys for the CMS plugin — matches the keys returned by
 * `stackClient.router.getRoute(path).routeKey`.
 */
type CMSRouteKey = "dashboard" | "contentList" | "newContent" | "editContent";
interface CMSPrefetchForRoute {
    (key: "dashboard" | "newContent", qc: QueryClient): Promise<void>;
    (key: "contentList", qc: QueryClient, params: {
        typeSlug: string;
    }): Promise<void>;
    (key: "editContent", qc: QueryClient, params: {
        typeSlug: string;
        id: string;
    }): Promise<void>;
}
/**
 * CMS backend plugin
 * Provides API endpoints for managing content types and content items
 *
 * @param config - Configuration with content types and optional hooks
 */
declare const cmsBackendPlugin: (config: CMSBackendConfig) => _btst_stack_plugins_api.BackendPlugin<{
    listContentTypes: better_call.StrictEndpoint<"/content-types", {
        method: "GET";
    }, {
        itemCount: number;
        createdAt: string;
        updatedAt: string;
        name: string;
        id: string;
        slug: string;
        description?: string | undefined;
        jsonSchema: string;
        fieldConfig?: string | undefined;
        autoFormVersion?: number | undefined;
    }[]>;
    getContentTypeBySlug: better_call.StrictEndpoint<"/content-types/:slug", {
        method: "GET";
        params: z.ZodObject<{
            slug: z.ZodString;
        }, z.core.$strip>;
    }, SerializedContentType>;
    listContentItems: better_call.StrictEndpoint<"/content/:typeSlug", {
        method: "GET";
        params: z.ZodObject<{
            typeSlug: z.ZodString;
        }, z.core.$strip>;
        query: z.ZodObject<{
            slug: z.ZodOptional<z.ZodString>;
            limit: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
            offset: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
        }, z.core.$strip>;
    }, {
        items: SerializedContentItemWithType[];
        total: number;
        limit?: number;
        offset?: number;
    }>;
    getContentItem: better_call.StrictEndpoint<"/content/:typeSlug/:id", {
        method: "GET";
        params: z.ZodObject<{
            typeSlug: z.ZodString;
            id: z.ZodString;
        }, z.core.$strip>;
    }, SerializedContentItemWithType<Record<string, unknown>>>;
    createContentItem: better_call.StrictEndpoint<"/content/:typeSlug", {
        method: "POST";
        params: z.ZodObject<{
            typeSlug: z.ZodString;
        }, z.core.$strip>;
        body: z.ZodObject<{
            slug: z.ZodString;
            data: z.ZodObject<{}, z.core.$loose>;
        }, z.core.$strip>;
    }, {
        parsedData: Record<string, unknown>;
        createdAt: string;
        updatedAt: string;
        id: string;
        slug: string;
        contentTypeId: string;
        data: string;
        authorId?: string | undefined;
    }>;
    updateContentItem: better_call.StrictEndpoint<"/content/:typeSlug/:id", {
        method: "PUT";
        params: z.ZodObject<{
            typeSlug: z.ZodString;
            id: z.ZodString;
        }, z.core.$strip>;
        body: z.ZodObject<{
            slug: z.ZodOptional<z.ZodString>;
            data: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
        }, z.core.$strip>;
    }, SerializedContentItemWithType<Record<string, unknown>>>;
    deleteContentItem: better_call.StrictEndpoint<"/content/:typeSlug/:id", {
        method: "DELETE";
        params: z.ZodObject<{
            typeSlug: z.ZodString;
            id: z.ZodString;
        }, z.core.$strip>;
    }, {
        success: boolean;
    }>;
    getContentItemPopulated: better_call.StrictEndpoint<"/content/:typeSlug/:id/populated", {
        method: "GET";
        params: z.ZodObject<{
            typeSlug: z.ZodString;
            id: z.ZodString;
        }, z.core.$strip>;
    }, {
        _relations: Record<string, SerializedContentItemWithType<Record<string, unknown>>[]>;
        parsedData: Record<string, unknown>;
        contentType?: SerializedContentType;
        createdAt: string;
        updatedAt: string;
        id: string;
        slug: string;
        contentTypeId: string;
        data: string;
        authorId?: string | undefined;
    }>;
    listContentByRelation: better_call.StrictEndpoint<"/content/:typeSlug/by-relation", {
        method: "GET";
        params: z.ZodObject<{
            typeSlug: z.ZodString;
        }, z.core.$strip>;
        query: z.ZodObject<{
            field: z.ZodString;
            targetId: z.ZodString;
            limit: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
            offset: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
        }, z.core.$strip>;
    }, {
        items: SerializedContentItemWithType<Record<string, unknown>>[];
        total: number;
        limit: number;
        offset: number;
    }>;
    getInverseRelations: better_call.StrictEndpoint<"/content-types/:slug/inverse-relations", {
        method: "GET";
        params: z.ZodObject<{
            slug: z.ZodString;
        }, z.core.$strip>;
        query: z.ZodObject<{
            itemId: z.ZodOptional<z.ZodString>;
        }, z.core.$strip>;
    }, {
        inverseRelations: InverseRelation[];
    }>;
    listInverseRelationItems: better_call.StrictEndpoint<"/content-types/:slug/inverse-relations/:sourceType", {
        method: "GET";
        params: z.ZodObject<{
            slug: z.ZodString;
            sourceType: z.ZodString;
        }, z.core.$strip>;
        query: z.ZodObject<{
            itemId: z.ZodString;
            fieldName: z.ZodString;
            limit: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
            offset: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
        }, z.core.$strip>;
    }, {
        items: SerializedContentItemWithType<Record<string, unknown>>[];
        total: number;
        limit: number;
        offset: number;
    }>;
}, {
    getAllContentTypes: () => Promise<SerializedContentType[]>;
    getAllContentItems: (contentTypeSlug: string, params?: Parameters<typeof getAllContentItems>[2]) => Promise<{
        items: SerializedContentItemWithType[];
        total: number;
        limit?: number;
        offset?: number;
    }>;
    getContentItemBySlug: (contentTypeSlug: string, slug: string) => Promise<SerializedContentItemWithType<Record<string, unknown>> | null>;
    getContentItemById: (id: string) => Promise<SerializedContentItemWithType<Record<string, unknown>> | null>;
    prefetchForRoute: CMSPrefetchForRoute;
    createContentItem: (typeSlug: string, input: Parameters<typeof createCMSContentItem>[2]) => Promise<SerializedContentItem>;
}>;
type CMSApiRouter = ReturnType<ReturnType<typeof cmsBackendPlugin>["routes"]>;

/**
 * Internal query key constants for the CMS plugin.
 * Shared between query-keys.ts (HTTP path) and prefetchForRoute (DB path)
 * to prevent key drift between SSR loaders and SSG prefetching.
 */
interface ContentListDiscriminator {
    typeSlug: string;
    limit: number;
    offset: number;
}
/** Full query key builders — use these with queryClient.setQueryData() */
declare const CMS_QUERY_KEYS: {
    /**
     * Key for the cmsTypes.list() query.
     * Full key: ["cmsTypes", "list", "list"]
     */
    typesList: () => readonly ["cmsTypes", "list", "list"];
    /**
     * Key for the cmsContent.list({ typeSlug, limit, offset }) query.
     * Full key: ["cmsContent", "list", { typeSlug, limit, offset }]
     */
    contentList: (params: {
        typeSlug: string;
        limit?: number;
        offset?: number;
    }) => readonly ["cmsContent", "list", ContentListDiscriminator];
    /**
     * Key for the cmsContent.detail(typeSlug, id) query.
     * Full key: ["cmsContent", "detail", typeSlug, id]
     */
    contentDetail: (typeSlug: string, id: string) => readonly ["cmsContent", "detail", string, string];
};

export { cmsBackendPlugin as c, getAllContentItems as d, getContentItemBySlug as e, getContentItemById as f, getAllContentTypes as g, serializeContentItem as h, serializeContentItemWithType as i, createCMSContentItem as j, CMS_QUERY_KEYS as l, serializeContentType as s };
export type { CMSApiRouter as C, ContentListDiscriminator as a, CMSRouteKey as b, CreateCMSContentItemInput as k };
