import { JobRunRow } from './job-orchestration.schema.js';
import { JobRunSummary } from './job-run-service.protocol.js';
import 'drizzle-orm/pg-core';
import 'drizzle-orm';
import '../../../job-orchestrator.protocol-ZuJ3ow-O.js';
import '../events/event-bus.protocol.js';
import '../../types/drizzle.js';
import 'drizzle-orm/node-postgres';
import '@nestjs/common';
import '../events/event-registry.js';

/**
 * Keyset (seek) cursor codec for `IJobRunService.listJobRuns` (OBS-LIST-1).
 *
 * The list is ordered `created_at DESC, id DESC`. The cursor encodes the
 * `(createdAt, id)` of the last row on the previous page so the next page
 * can seek with `WHERE (created_at, id) < (cursorCreatedAt, cursorId)`
 * rather than an `OFFSET`. Keyset pagination stays O(log n) on deep pages
 * and is stable as new rows arrive at the head.
 *
 * The cursor is opaque to consumers: a base64url-encoded JSON tuple. Shape
 * is an implementation detail — never parse it outside this module.
 *
 * Also hosts `toJobRunSummary`, the single `JobRunRow → JobRunSummary`
 * projection shared by both backends so the narrow shape stays in sync.
 */

interface JobRunKeyset {
    /** `created_at` of the last row on the previous page. */
    createdAt: Date;
    /** `id` (UUID) tie-break of the last row on the previous page. */
    id: string;
}
/** Default page size when `limit` is omitted. */
declare const DEFAULT_LIST_LIMIT = 50;
/** Hard upper bound on page size to keep a single read bounded. */
declare const MAX_LIST_LIMIT = 200;
/** Clamp a caller-supplied `limit` into `[1, MAX_LIST_LIMIT]`. */
declare function clampLimit(limit: number | undefined): number;
declare function encodeKeysetCursor(keyset: JobRunKeyset): string;
/**
 * Decode an opaque cursor back into its `(createdAt, id)` keyset. Returns
 * `null` for a malformed cursor so callers can treat garbage input as
 * "start from the beginning" rather than throwing on user-supplied data.
 */
declare function decodeKeysetCursor(cursor: string): JobRunKeyset | null;
/**
 * Project a raw `job_run` row into the narrow `JobRunSummary` shape exposed
 * by `listJobRuns`. `errorMessage` is pulled from the jsonb `error.message`.
 */
declare function toJobRunSummary(r: JobRunRow): JobRunSummary;

export { DEFAULT_LIST_LIMIT, type JobRunKeyset, MAX_LIST_LIMIT, clampLimit, decodeKeysetCursor, encodeKeysetCursor, toJobRunSummary };
