/**
 * Types for LLM HTML-to-Manifest Conversion
 *
 * Defines input/output types for converting HTML (with Tailwind/CSS)
 * into declarative block manifests via LLM.
 */
import type { Theme, CustomCssRuleInput, CustomCssAtRuleInput } from '../contracts';
import type { SdkCustomBlock } from '../config/types';
import type { ThemePatchOp } from './validation/output-schema';
import type { AiRuntime } from '../ai/runtime';
/**
 * Summary of a content type for LLM context.
 */
export interface ContentTypeSummaryForConverter {
    /** Content type key (e.g., 'event', 'testimonial') */
    key: string;
    /** Human-readable name */
    name: string;
    /** Description for LLM context */
    description?: string;
    /** Schema fields */
    fields: Array<{
        id: string;
        type: string;
        label?: string;
    }>;
    /** Whether entries have their own pages */
    isRouted: boolean;
}
/**
 * Input for HTML-to-manifest conversion.
 */
export interface HtmlToManifestInput {
    /** HTML content to convert (with Tailwind classes or inline styles) */
    html: string;
    /** Optional separate CSS file content */
    css?: string;
    /** Theme JSON - required for mapping styles to tokens */
    theme: Theme;
    /**
     * Hint for block boundary detection.
     * - 'single': Force output to be a single block
     * - 'multiple': Allow splitting into multiple blocks
     * - 'auto': Let LLM decide based on content structure
     * @default 'auto'
     */
    expectedBlockCount?: 'single' | 'multiple' | 'auto';
    /**
     * Available content types for the LLM to consider.
     * When provided, the LLM may decide to create content entries
     * instead of using repeater fields for list-like content.
     */
    availableContentTypes?: ContentTypeSummaryForConverter[];
}
/**
 * Configuration for a content entry to create.
 */
export interface EntryConfigForConverter {
    /** Unique slug-safe identifier */
    identifier: string;
    /** Content type key */
    contentType: string;
    /** Entry title */
    title: string;
    /** Entry data matching the content type schema */
    data: Record<string, unknown>;
    /** Entry status */
    status?: 'draft' | 'published';
}
/**
 * Configuration for a new content type to create.
 */
export interface ContentTypeConfigForConverter {
    /** Content type key (slug-safe) */
    key: string;
    /** Human-readable name */
    name: string;
    /** Description */
    description?: string;
    /** Schema fields */
    fields: Array<{
        id: string;
        type: string;
        label: string;
        required?: boolean;
        description?: string;
    }>;
    /** Whether entries should be routable */
    isRouted: boolean;
}
/**
 * Output from HTML-to-manifest conversion.
 *
 * Contains generated blocks plus optional styling that couldn't
 * be mapped directly to theme tokens.
 */
export interface HtmlToManifestOutput {
    /** Generated custom block definitions */
    blocks: SdkCustomBlock[];
    /**
     * Theme patches for styles that should be site-wide.
     * Only included if the HTML uses colors/styles not in the theme.
     */
    themePatch?: ThemePatchOp[];
    /**
     * Custom CSS rules for block-specific styles that can't be
     * expressed via theme tokens or inline styles.
     */
    customCssRules?: CustomCssRuleInput[];
    /**
     * Custom CSS at-rules for responsive styles (@media), animations (@keyframes), etc.
     */
    customCssAtRules?: CustomCssAtRuleInput[];
    /**
     * Content entries to create.
     * Generated when the LLM decides to use content types.
     */
    entries?: EntryConfigForConverter[];
    /**
     * Custom content types to create.
     * Generated when no existing content type fits.
     */
    contentTypes?: ContentTypeConfigForConverter[];
}
/**
 * Details of a single conversion attempt for debugging.
 */
export interface AttemptResult {
    /** Attempt number (1-based) */
    attempt: number;
    /** Validation errors found in this attempt */
    validationErrors: string[];
    /** Raw LLM output (for debugging) */
    rawOutput?: unknown;
}
/**
 * Successful conversion result.
 */
export interface ConversionSuccess {
    success: true;
    output: HtmlToManifestOutput;
    /** Number of attempts needed to get valid output */
    attempts: number;
}
/**
 * Failed conversion result with error details.
 */
export interface ConversionFailure {
    success: false;
    /** Human-readable error message */
    error: string;
    /** Details of each attempt for debugging */
    attempts: AttemptResult[];
}
/**
 * Result of HTML-to-manifest conversion.
 * Either succeeds with output or fails with detailed error info.
 */
export type ConversionResult = ConversionSuccess | ConversionFailure;
/**
 * Color info for LLM context.
 */
export interface ThemeColorSummary {
    /** Token name (e.g., 'primary', 'accent') */
    token: string;
    /** Hex value (e.g., '#2563eb') */
    hex: string;
    /** Usage hint (e.g., 'buttons, links, accents') */
    usage: string;
}
/**
 * Simplified theme summary for LLM prompts.
 * Provides relevant theme info without overwhelming the context.
 */
export interface ThemeSummaryForLLM {
    /** Available color palette with usage hints */
    palette: ThemeColorSummary[];
    /** Typography info */
    typography: {
        bodyFamily: string;
        headingFamily: string;
        weights: string[];
    };
    /** Spacing preset name */
    spacing: string;
    /** Corner style with actual radius value */
    corners: string;
}
/**
 * Options for the converter.
 */
export interface ConverterOptions {
    /** AI runtime implementation (provider-specific; injected by caller) */
    ai: AiRuntime;
    /** Max retry attempts for validation failures */
    maxRetries?: number;
    /** Override the AI model (default: 'gpt-5-mini') */
    model?: string;
    /** Temperature for LLM (default: 0.2 for more deterministic output) */
    temperature?: number;
    /** Callback for progress updates */
    onProgress?: (message: string) => void;
    /**
     * Directory path for debug output files.
     * When provided, writes:
     * - attempt-N-output.json: Raw LLM output for each attempt
     * - attempt-N-prompt.txt: Full prompt sent to the LLM
     * - attempt-N-rationale.txt: LLM's explanation of fixes (for retries)
     */
    debugDir?: string;
}
