/**
 * webhook/types.ts
 *
 * Types for the Sanity Content Lake webhook payload and the
 * event-driven evaluation trigger system.
 *
 * @see https://www.sanity.io/docs/webhooks
 * @see docs/design-docs/report-store/visibility-workflows.md
 */
/** Evaluation dispatch request (sent to GitHub Actions) */
export interface DispatchRequest {
    /** Feature areas to evaluate */
    areas: string[];
    /** The document that triggered this evaluation */
    documentId?: string;
    /** Document slug */
    documentSlug?: string;
    /** Evaluation mode */
    mode?: string;
    /** Specific task IDs to evaluate */
    taskIds: string[];
}
/**
 * Sanity webhook payload shape.
 *
 * When a GROQ-powered webhook fires, Sanity POSTs a JSON body with
 * the matching document and operation metadata.
 */
export interface SanityWebhookPayload {
    /** The ID of the dataset */
    dataset?: string;
    /** The IDs of the documents that triggered the webhook */
    ids: {
        /** The created document ID (for create operations) */
        created?: string;
        /** The deleted document ID (for delete operations) */
        deleted?: string;
        /** The updated document ID (for update operations) */
        updated?: string;
    };
    /** The operation that triggered the webhook */
    operation: "create" | "delete" | "update";
    /** The ID of the project */
    projectId?: string;
    /** The projected document data (shape depends on webhook GROQ projection) */
    result?: {
        _id: string;
        _type: string;
        slug?: {
            current: string;
        };
        [key: string]: unknown;
    };
}
/** Configuration for the webhook handler */
export interface WebhookHandlerConfig {
    /**
     * Budget: maximum evaluations per day.
     * When exceeded, webhooks are acknowledged but not dispatched.
     * Default: 20
     */
    dailyBudget?: number;
    /**
     * Debounce window in milliseconds.
     * Rapid edits within this window are coalesced into a single evaluation.
     * Default: 300_000 (5 minutes)
     */
    debounceMs?: number;
    /**
     * The GitHub repository to dispatch to (owner/repo format).
     * Default: "sanity-labs/ai-literacy-framework"
     */
    githubRepo?: string;
    /**
     * GitHub personal access token for dispatching repository_dispatch events.
     * Required for triggering evaluations.
     */
    githubToken: string;
    /**
     * Path to the eval package root (for building reverse mappings).
     * Default: process.cwd()
     */
    rootDir?: string;
    /**
     * Sanity webhook secret for verifying payload authenticity.
     * If provided, the handler validates the X-Sanity-Webhook-Signature header.
     */
    webhookSecret?: string;
}
/** Result of handling a webhook */
export type WebhookResult = {
    status: "acknowledged";
    reason: string;
} | {
    status: "debounced";
    pendingSlugs: string[];
    windowExpiresAt: string;
} | {
    status: "dispatched";
    areas: string[];
    taskIds: string[];
} | {
    status: "ignored";
    reason: string;
} | {
    status: "rate-limited";
    dailyCount: number;
    dailyBudget: number;
};
