import { z } from 'zod';
import { VNode } from 'preact';

/**
 * Progress notification for long-running operations
 */
interface ProgressNotification {
    progress: number;
    total?: number;
    message?: string;
    rate?: number;
    eta?: number;
}
/**
 * Progress callback type
 */
type ProgressCallback = (notification: ProgressNotification) => Promise<void>;

/**
 * Interface for content formatters (human-editable content formatting)
 *
 * ContentFormatters handle bidirectional transformation between structured data
 * and human-editable markdown templates. Unlike SchemaFormatters which are for
 * one-way API response formatting, ContentFormatters support parsing edited
 * content back into structured data.
 */
interface ContentFormatter<T = unknown> {
    /**
     * Format structured data into human-editable markdown
     * @param data - The structured data to format
     * @returns Human-editable markdown representation
     */
    format(data: T): string;
    /**
     * Parse human-editable markdown back into structured data
     * @param content - The markdown content to parse
     * @returns Structured data parsed from the markdown
     * @throws Error if the content cannot be parsed
     */
    parse(content: string): T;
}

/**
 * Component type for layouts - using Preact
 * Returns a Preact VNode
 */
type ComponentType<P = unknown> = (props: P) => VNode;
/**
 * A runtime script that a template depends on. Site-builder collects
 * these per route across all templates rendered on the page, dedupes
 * by `src`, and injects them as <script> tags.
 *
 * Use this for non-hydration runtime scripts (background canvases,
 * scroll observers, decorative animations) that should ONLY load on
 * pages where the template actually renders — unlike the plugin-level
 * head-script registration which fires on every page.
 */
interface RuntimeScript {
    src: string;
    defer?: boolean;
    module?: boolean;
}
/**
 * Helper function to create a type-safe component that automatically parses props
 * using the provided Zod schema
 *
 * Supports transformation between schema type and component type (e.g., enrichment)
 * @param TSchema - Type validated by schema (e.g., with optional url/typeLabel)
 * @param TComponent - Type expected by component (e.g., with required url/typeLabel)
 */
declare function createTypedComponent<TSchema, TComponent = TSchema>(schema: z.ZodType<TSchema, z.ZodTypeDef, unknown>, component: ComponentType<TComponent>): ComponentType<unknown>;
/**
 * Unified template interface that bundles content generation and view rendering
 * This is the single source of truth for what constitutes a template
 */
interface Template extends Omit<z.infer<typeof TemplateSchema>, "schema" | "layout" | "formatter"> {
    schema: z.ZodType<unknown, z.ZodTypeDef, unknown>;
    layout?: {
        component?: ComponentType<unknown>;
        fullscreen?: boolean;
    };
    formatter?: ContentFormatter<unknown>;
    /**
     * Whether to retrieve relevant entities from the knowledge base
     * and inject them as context before AI generation. Default: false.
     */
    useKnowledgeContext?: boolean;
    /**
     * Runtime script dependencies. Loaded only on routes where this
     * template actually renders — site-builder collects from all
     * templates on a route, dedupes by src, and injects into <head>.
     */
    runtimeScripts?: RuntimeScript[];
}
/**
 * Helper to create a template with automatic component wrapping
 *
 * Supports transformation between schema type and component type (e.g., enrichment)
 * @param TSchema - Type validated by schema (datasource output)
 * @param TComponent - Type expected by component (after enrichment)
 */
declare function createTemplate<TSchema = unknown, TComponent = TSchema>(template: Omit<Template, "layout" | "schema"> & {
    schema: z.ZodType<TSchema, z.ZodTypeDef, unknown>;
    layout?: {
        component?: ComponentType<TComponent>;
        fullscreen?: boolean;
    };
    runtimeScripts?: RuntimeScript[];
}): Template;
/**
 * Template schema for validation
 */
declare const TemplateSchema: z.ZodObject<{
    name: z.ZodString;
    description: z.ZodString;
    schema: z.ZodAny;
    basePrompt: z.ZodOptional<z.ZodString>;
    useKnowledgeContext: z.ZodOptional<z.ZodBoolean>;
    requiredPermission: z.ZodEnum<["anchor", "trusted", "public"]>;
    formatter: z.ZodOptional<z.ZodAny>;
    layout: z.ZodOptional<z.ZodObject<{
        component: z.ZodAny;
        fullscreen: z.ZodOptional<z.ZodBoolean>;
    }, "strip", z.ZodTypeAny, {
        component?: any;
        fullscreen?: boolean | undefined;
    }, {
        component?: any;
        fullscreen?: boolean | undefined;
    }>>;
    dataSourceId: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
    name: string;
    description: string;
    requiredPermission: "anchor" | "trusted" | "public";
    schema?: any;
    basePrompt?: string | undefined;
    useKnowledgeContext?: boolean | undefined;
    formatter?: any;
    layout?: {
        component?: any;
        fullscreen?: boolean | undefined;
    } | undefined;
    dataSourceId?: string | undefined;
}, {
    name: string;
    description: string;
    requiredPermission: "anchor" | "trusted" | "public";
    schema?: any;
    basePrompt?: string | undefined;
    useKnowledgeContext?: boolean | undefined;
    formatter?: any;
    layout?: {
        component?: any;
        fullscreen?: boolean | undefined;
    } | undefined;
    dataSourceId?: string | undefined;
}>;
type TemplateInput = z.infer<typeof TemplateSchema>;

/**
 * Site content entity types
 */
declare const SiteContentEntityTypeSchema: z.ZodEnum<["site-content-preview", "site-content-production"]>;
type SiteContentEntityType = z.infer<typeof SiteContentEntityTypeSchema>;
/**
 * Renderer output formats supported by view templates.
 */
declare const OutputFormatSchema: z.ZodEnum<["web", "image", "pdf"]>;
type OutputFormat = z.infer<typeof OutputFormatSchema>;
/**
 * View template schema
 */
declare const ViewTemplateSchema: z.ZodObject<{
    name: z.ZodString;
    schema: z.ZodAny;
    description: z.ZodOptional<z.ZodString>;
    pluginId: z.ZodString;
    renderers: z.ZodObject<{
        web: z.ZodOptional<z.ZodUnion<[z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>, z.ZodString]>>;
        image: z.ZodOptional<z.ZodUnion<[z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>, z.ZodString]>>;
        pdf: z.ZodOptional<z.ZodUnion<[z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>, z.ZodString]>>;
    }, "strip", z.ZodTypeAny, {
        web?: string | ((...args: unknown[]) => unknown) | undefined;
        image?: string | ((...args: unknown[]) => unknown) | undefined;
        pdf?: string | ((...args: unknown[]) => unknown) | undefined;
    }, {
        web?: string | ((...args: unknown[]) => unknown) | undefined;
        image?: string | ((...args: unknown[]) => unknown) | undefined;
        pdf?: string | ((...args: unknown[]) => unknown) | undefined;
    }>;
}, "strip", z.ZodTypeAny, {
    name: string;
    pluginId: string;
    renderers: {
        web?: string | ((...args: unknown[]) => unknown) | undefined;
        image?: string | ((...args: unknown[]) => unknown) | undefined;
        pdf?: string | ((...args: unknown[]) => unknown) | undefined;
    };
    description?: string | undefined;
    schema?: any;
}, {
    name: string;
    pluginId: string;
    renderers: {
        web?: string | ((...args: unknown[]) => unknown) | undefined;
        image?: string | ((...args: unknown[]) => unknown) | undefined;
        pdf?: string | ((...args: unknown[]) => unknown) | undefined;
    };
    description?: string | undefined;
    schema?: any;
}>;
/**
 * Renderer types for different output formats
 */
type WebRenderer<T = unknown> = ComponentType<T> | string;
type ImageRenderer<T = unknown> = ComponentType<T> | string;
type PdfRenderer<T = unknown> = ComponentType<T> | string;
/**
 * View template with support for multiple output formats
 */
interface ViewTemplate<T = unknown> {
    name: string;
    schema: z.ZodType<T>;
    description?: string;
    pluginId: string;
    renderers: {
        web?: WebRenderer<T>;
        image?: ImageRenderer<T>;
        pdf?: PdfRenderer<T>;
    };
    fullscreen?: boolean;
    providerId?: string;
    formatter?: ContentFormatter<T>;
    /** Runtime script dependencies (see Template.runtimeScripts). */
    runtimeScripts?: RuntimeScript[];
}
/**
 * View template registry interface
 */
interface ViewTemplateRegistry {
    get(name: string): ViewTemplate<unknown> | undefined;
    list(): ViewTemplate<unknown>[];
    validate(templateName: string, content: unknown): boolean;
}
/**
 * Site builder options
 */
declare const SiteBuilderOptionsSchema: z.ZodObject<{
    enableContentGeneration: z.ZodDefault<z.ZodBoolean>;
    outputDir: z.ZodString;
    workingDir: z.ZodOptional<z.ZodString>;
    environment: z.ZodDefault<z.ZodEnum<["preview", "production"]>>;
    siteConfig: z.ZodOptional<z.ZodObject<{
        title: z.ZodString;
        description: z.ZodString;
        url: z.ZodOptional<z.ZodString>;
    }, "strip", z.ZodTypeAny, {
        description: string;
        title: string;
        url?: string | undefined;
    }, {
        description: string;
        title: string;
        url?: string | undefined;
    }>>;
}, "strip", z.ZodTypeAny, {
    enableContentGeneration: boolean;
    outputDir: string;
    environment: "preview" | "production";
    workingDir?: string | undefined;
    siteConfig?: {
        description: string;
        title: string;
        url?: string | undefined;
    } | undefined;
}, {
    outputDir: string;
    enableContentGeneration?: boolean | undefined;
    workingDir?: string | undefined;
    environment?: "preview" | "production" | undefined;
    siteConfig?: {
        description: string;
        title: string;
        url?: string | undefined;
    } | undefined;
}>;
type SiteBuilderOptions = z.infer<typeof SiteBuilderOptionsSchema>;
/**
 * Build result schema
 */
declare const BuildResultSchema: z.ZodObject<{
    success: z.ZodBoolean;
    routesBuilt: z.ZodNumber;
    errors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
    warnings: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
    success: boolean;
    routesBuilt: number;
    errors?: string[] | undefined;
    warnings?: string[] | undefined;
}, {
    success: boolean;
    routesBuilt: number;
    errors?: string[] | undefined;
    warnings?: string[] | undefined;
}>;
type BuildResult = z.infer<typeof BuildResultSchema>;
/**
 * Site builder interface
 */
interface SiteBuilder {
    build(options: SiteBuilderOptions, progress?: ProgressCallback): Promise<BuildResult>;
}

export { BuildResultSchema, SiteBuilderOptionsSchema, SiteContentEntityTypeSchema, TemplateSchema, ViewTemplateSchema, createTemplate, createTypedComponent };
export type { BuildResult, ComponentType, OutputFormat, RuntimeScript, SiteBuilder, SiteBuilderOptions, SiteContentEntityType, Template, TemplateInput, ViewTemplate, ViewTemplateRegistry, WebRenderer };
