import { Querier } from '@platform-modules/db';
import { C as CommentInput, a as CommentsSchema, b as CommentTarget, S as StoreOpts, A as Actor, E as EntityRef, c as Comment, L as ListQuery, P as Page, d as CommentStatus, e as CommentAuthor } from './errors-D4Ae3zmj.js';
export { f as CommentAuthzError, g as CommentNotFoundError, h as CommentSanitizationError, i as CommentValidationError, I as InvalidCursorError, j as Sanitize, k as comments, l as commentsSchema, m as commentsTableSql, n as isCommentError } from './errors-D4Ae3zmj.js';
import 'drizzle-orm/pg-core';

/** Maximum raw body length (cheap-DoS floor, spec §3). */
declare const MAX_BODY_LEN = 10000;
/** Normalized comment input — parentId always explicit null when absent. */
type NormalizedCommentInput = CommentInput & {
    parentId: string | null;
};
/**
 * Validator-agnostic boundary normalization (spec §3, coding-standard).
 * Throws CommentValidationError for: empty body, body > MAX_BODY_LEN, bad target, bad author.
 */
declare function normalizeCommentInput(raw: CommentInput): NormalizedCommentInput;

/**
 * list — flat paginated Page<Comment> (spec §3).
 * Default: status='published', order='oldest', limit=20.
 * Non-published statuses require actor.canModerate → CommentAuthzError.
 * Keyset: NUMERIC (createdAtMs, seq) — collation-safe (spec §3 ordering floor).
 */
declare function list(db: Querier<CommentsSchema>, target: CommentTarget, query?: ListQuery, actor?: Actor, _opts?: StoreOpts): Promise<Page<Comment>>;
/**
 * getById — returns Comment or null; same guest-email redaction as list (spec §3).
 * Returns tombstoned rows (trashed rows are still valid Comment shapes).
 */
declare function getById(db: Querier<CommentsSchema>, id: string, actor?: Actor, _opts?: StoreOpts): Promise<Comment | null>;
/**
 * post — create a new comment (spec §3).
 * sanitize REQUIRED (hard-floor #1); missing/non-function → CommentSanitizationError.
 * initialStatus defaults to 'pending'; non-moderator passing non-pending → CommentAuthzError.
 * depth stored at insert: parent.depth+1 capped at MAX_DEPTH; 0 for top-level.
 * Validates parent exists + shares same target.
 */
declare function post(db: Querier<CommentsSchema>, input: CommentInput, actor: Actor | null, sanitize: unknown, opts?: StoreOpts): Promise<EntityRef>;
/**
 * edit — update body + re-sanitize bodyHtml + bump editedAt (spec §3).
 * sanitize REQUIRED (hard-floor #1).
 * authz: author or canModerate (hard-floor #2).
 */
declare function edit(db: Querier<CommentsSchema>, id: string, body: string, actor: Actor, sanitize: unknown, _opts?: StoreOpts): Promise<EntityRef>;
/**
 * setStatus — moderation transition (spec §3).
 * Requires actor.canModerate (hard-floor #2).
 */
declare function setStatus(db: Querier<CommentsSchema>, id: string, status: CommentStatus, actor: Actor, _opts?: StoreOpts): Promise<EntityRef>;
/**
 * remove — tombstone if children exist, else hard-delete (spec §3 deletion floor).
 * authz: author or canModerate (hard-floor #2).
 */
declare function remove(db: Querier<CommentsSchema>, id: string, actor: Actor, _opts?: StoreOpts): Promise<void>;
/**
 * count — published-only count for "N comments" display (spec §3).
 */
declare function count(db: Querier<CommentsSchema>, target: CommentTarget, _opts?: StoreOpts): Promise<number>;
/**
 * listForModeration — CROSS-TARGET moderation queue (spec §3 hard-floor #5).
 * NO target filter — scans all rows, filtered by status only.
 * actor REQUIRED + canModerate UNCONDITIONAL (fail-closed) — cross-target enumeration is
 * privileged even for published rows. Default status=['pending'], default order='newest'.
 * Keyset (createdAtMs, seq) is globally sound (seq = per-store bigserial — total order
 * across all targets). Guest email VISIBLE (moderator-only by construction).
 */
declare function listForModeration(db: Querier<CommentsSchema>, query: ListQuery | undefined, actor: Actor, _opts?: StoreOpts): Promise<Page<Comment>>;

/**
 * Object-level authz — IDOR floor (spec §3).
 * Allowed: authoring user OR actor.canModerate.
 * Guest-authored comments: no session identity → only a moderator may modify (standard comment behavior).
 */
declare function assertCanModify(actor: Actor | null, action: string, owner: CommentAuthor, commentId: string): void;
/**
 * Moderation transition gate (spec §3).
 * setStatus requires canModerate.
 */
declare function assertCanModerate(actor: Actor, action: string, commentId: string): void;

type Keyset = {
    createdAtMs: number;
    seq: number;
};
declare function encodeCursor(key: Keyset): string;
declare function decodeCursor(cursor: string): Keyset;
type ClampLimitOptions = {
    defaultLimit?: number;
    maxLimit?: number;
};
/** Clamp untrusted limit — non-finite/undefined/<=0 → default; huge → max. Never throws. */
declare function clampLimit(value: number | undefined, opts?: ClampLimitOptions): number;

export { Actor, type ClampLimitOptions, Comment, CommentAuthor, CommentInput, CommentStatus, CommentTarget, CommentsSchema, EntityRef, type Keyset, ListQuery, MAX_BODY_LEN, Page, StoreOpts, assertCanModerate, assertCanModify, clampLimit, count, decodeCursor, edit, encodeCursor, getById, list, listForModeration, normalizeCommentInput, post, remove, setStatus };
