import { chunks, first, placeholders, run } from "./db";
import { accountDb, repoDb, stmt } from "./scoped-db";
import type { ScopedDb, ScopedStatement, ScopedValue } from "./scoped-db";
import { forgetLocator, locate } from "./scoped-db/locators";
import { scopedId } from "./scoped-db/ids";
import { allocateIssueNumber, indexIssue } from "./issues";
import type { IssueRow } from "./issues";
import { addIssueEvent } from "./pulls";
import { assertBelowCap } from "./limits";
import { issuesChanged } from "./repo-state";
import type { RepoRow } from "~/lib/types";
/** Per-scope count caps for workstream 6 entities; kept here so `limits.ts` stays merge-friendly. */
export const PLANNING_CAPS = {
milestonesPerRepo: 100,
issueTypesPerRepo: 25,
subIssuesPerParent: 100,
pinnedPerRepo: 3,
projectsPerOwner: 100,
fieldsPerProject: 30,
optionsPerField: 50,
itemsPerProject: 1000,
categoriesPerRepo: 25,
discussionCommentsPerThread: 2000,
} as const;
/** `db` is where the counted table lives: the D1 directory by default, else a `repoDb` / `accountDb`. */
export async function assertCount(
sql: string,
param: string,
cap: number,
what: string,
db: Pick<ScopedDb, "first"> = { first },
): Promise<void> {
const row = await db.first<{ count: number }>(sql, param);
assertBelowCap(row?.count ?? 0, cap, what);
}
export type Progress = { total: number; closed: number };