/**
 * Types for prebuild cache functionality
 *
 * The prebuild cache generates static JSON files at build time that serve
 * as a last-resort fallback when the CMS is unavailable.
 */
import type { RiverbankClient, SiteResponse, PageResponse, EntriesResponse } from '../client/types';
import type { NavigationItemRecord } from '../public-api/contracts';
/**
 * Content types that can be included in the prebuild cache.
 */
export type PrebuildContentType = 'site' | 'pages' | 'entries' | 'navigation' | 'forms';
/**
 * Progress callback data for prebuild operations.
 */
export interface PrebuildProgress {
    /** Current item number (1-indexed) */
    current: number;
    /** Total items to process */
    total: number;
    /** Description of current item being processed */
    item: string;
    /** Content type being processed */
    contentType: PrebuildContentType;
}
/**
 * Options for the prebuildCache function.
 */
export interface PrebuildOptions {
    /** Configured Riverbank client */
    client: RiverbankClient;
    /** Site ID to prebuild */
    siteId: string;
    /** Output directory for prebuild cache (e.g., '.riverbank-cache') */
    outputDir: string;
    /** Content types to include (default: all) */
    include?: PrebuildContentType[];
    /** Filter entries to specific content types (default: all configured) */
    contentTypes?: string[];
    /** Gzip compress output files (default: false) */
    compress?: boolean;
    /** Progress callback fired during generation */
    onProgress?: (progress: PrebuildProgress) => void;
}
/**
 * Result from prebuildCache function.
 */
export interface PrebuildResult {
    /** Whether prebuild completed successfully */
    success: boolean;
    /** Output directory path */
    outputDir: string;
    /** List of generated files (relative to outputDir) */
    files: string[];
    /** Total size of all files in bytes */
    totalSize: number;
    /** ISO timestamp when prebuild was generated */
    generatedAt: string;
    /** SHA256 checksum of manifest for validation */
    checksum: string;
    /** Any errors encountered (partial success possible) */
    errors?: string[];
}
/**
 * Manifest file structure for prebuild cache.
 */
export interface PrebuildManifest {
    /** Manifest version for compatibility checking */
    version: string;
    /** ISO timestamp when prebuild was generated */
    generatedAt: string;
    /** SHA256 checksum of manifest contents (excluding checksum field) */
    checksum: string;
    /** Site ID this prebuild is for */
    siteId: string;
    /** SDK version used to generate prebuild */
    sdkVersion: string;
    /** Mapping of cache keys to file paths */
    keyToFile: Record<string, string>;
    /** Content types included in this prebuild */
    includedTypes: PrebuildContentType[];
    /** Total number of files generated */
    fileCount: number;
    /** Total size in bytes */
    totalSize: number;
}
/**
 * Site cache file structure.
 */
export interface SiteCacheFile {
    /** Site data */
    data: SiteResponse;
    /** When this was generated */
    generatedAt: string;
}
/**
 * Page index file structure (list of all pages).
 */
export interface PageIndexFile {
    /** List of page paths and IDs */
    pages: Array<{
        path: string;
        pageId: string;
        title: string;
    }>;
    /** Total count */
    totalCount: number;
    /** When this was generated */
    generatedAt: string;
}
/**
 * Individual page cache file structure.
 */
export interface PageCacheFile {
    /** Page data */
    data: PageResponse;
    /** Original path */
    path: string;
    /** When this was generated */
    generatedAt: string;
}
/**
 * Entries cache file structure (all entries for a content type).
 */
export interface EntriesCacheFile {
    /** All entries for this content type */
    entries: EntriesResponse['entries'];
    /** Content type slug */
    contentType: string;
    /** Total count of entries */
    totalCount: number;
    /** When this was generated */
    generatedAt: string;
}
/**
 * Navigation cache file structure.
 */
export interface NavigationCacheFile {
    /** Navigation menu data */
    menus: Array<{
        /** Menu identifier (used as lookup key) */
        identifier: string | null;
        /** Menu ID (fallback if no identifier) */
        id: string;
        /** Menu display name */
        name: string;
        /** Navigation items in this menu */
        items: NavigationItemRecord[];
    }>;
    /** When this was generated */
    generatedAt: string;
}
/**
 * Forms cache file structure.
 */
export interface FormsCacheFile {
    /** All forms for this site */
    forms: Array<{
        /** Form ID */
        id: string;
        /** URL-friendly slug */
        slug: string;
        /** Form display name */
        name: string;
        /** Form schema (field definitions) */
        schema: Record<string, unknown>;
        /** Form settings */
        settings: Record<string, unknown>;
    }>;
    /** Total count of forms */
    totalCount: number;
    /** When this was generated */
    generatedAt: string;
}
/**
 * Prebuild configuration for the SDK client.
 * Added to ResilienceConfig.
 */
export interface PrebuildConfig {
    /**
     * Path to prebuild cache directory.
     * If set, enables prebuild fallback in resilient fetch.
     */
    prebuildDir?: string;
    /**
     * Maximum age in seconds for prebuild cache.
     * Prebuilds older than this are rejected.
     * @default 86400 (24 hours)
     */
    maxPrebuildAgeSec?: number;
}
