import type { Kysely } from 'kysely';
import type { LockWorkflow } from '@kici-dev/engine';
import type { Database } from '../db/types.js';
/**
 * Parsed registration row with typed fields.
 * DB stores lock_entry as JSON string and trigger_types as TEXT[],
 * but this interface exposes them as typed objects.
 */
export interface RegistrationRow {
    id: string;
    repo_identifier: string;
    workflow_name: string;
    lock_entry: LockWorkflow;
    trigger_types: string[];
    routing_key: string;
    provider_context: Record<string, unknown>;
    disabled: boolean;
    isGlobal: boolean;
    /**
     * Customer/org ID that owns this registration. Sourced from the source row
     * (sources or generic_webhook_sources joined on routing_key) and persisted
     * by replaceAll. Drives the (customer_id, eventName) lookup in
     * RegistrationIndex used by cross-source webhook delivery.
     */
    customerId: string;
    commitSha: string | null;
    sourceFile: string | null;
    created_at: Date;
    updated_at: Date;
}
/**
 * Options for replaceAll to pass commit tracking metadata.
 */
interface ReplaceAllOptions {
    /**
     * Customer/org ID that owns the registrations being written. REQUIRED —
     * persisted into workflow_registrations.customer_id (NOT NULL since
     * migration 020) and used by RegistrationIndex.byOrgAndEvent for
     * cross-source webhook lookup.
     */
    customerId: string;
    commitSha?: string;
    sourceFile?: string;
    /** Set of workflow names that should be marked as global */
    globalWorkflowNames?: Set<string>;
}
/**
 * DB CRUD for workflow_registrations table with atomic upsert-based replace-all.
 *
 * The replace-all pattern uses SELECT + UPDATE/INSERT + selective DELETE in a
 * single transaction. This preserves existing registration UUIDs (and their
 * cascaded cron_last_fired records) while still being atomic against concurrent
 * pushes.
 */
export declare class RegistrationStore {
    private readonly db;
    constructor(db: Kysely<Database>);
    /**
     * Atomically replace all registrations for a repo (scoped by routing key).
     *
     * Uses an upsert pattern that preserves existing registration IDs:
     * 1. SELECT existing rows for this routing_key + repo
     * 2. UPDATE rows whose workflow_name still exists in the incoming set
     * 3. INSERT rows for new workflow_names
     * 4. DELETE rows whose workflow_name is no longer in the incoming set
     *
     * This prevents cascade deletion of cron_last_fired records when workflows
     * are re-registered on every default-branch push.
     */
    replaceAll(repoIdentifier: string, workflows: LockWorkflow[], routingKey: string, providerContext: Record<string, unknown>, options: ReplaceAllOptions): Promise<void>;
    /**
     * Toggle the disabled state of a workflow registration.
     * Returns true if a row was updated, false if the ID was not found.
     */
    setDisabled(id: string, disabled: boolean): Promise<boolean>;
    /**
     * Get all registrations (for index loading on startup).
     */
    getAll(): Promise<RegistrationRow[]>;
    /**
     * Get registrations for a specific routing key.
     */
    getByRoutingKey(routingKey: string): Promise<RegistrationRow[]>;
    /**
     * Get registrations for a specific routing key + repo pair.
     */
    getByRoutingKeyAndRepo(routingKey: string, repoIdentifier: string): Promise<RegistrationRow[]>;
    /**
     * Get a single registration by ID. Returns null if not found.
     */
    getById(id: string): Promise<RegistrationRow | null>;
    /**
     * Delete a single registration by ID. Returns true if deleted.
     */
    deleteById(id: string): Promise<boolean>;
    /**
     * Delete all registrations for a routing key + repo pair.
     */
    deleteByRoutingKeyAndRepo(routingKey: string, repoIdentifier: string): Promise<void>;
    /**
     * Get the current registry version (for cluster sync).
     */
    getVersion(): Promise<number>;
    /**
     * Increment the registry version and return the new value.
     * Called after registration changes to notify peers via heartbeat.
     */
    bumpVersion(): Promise<number>;
}
export {};
//# sourceMappingURL=registration-store.d.ts.map