import { type BillingPlanBalance } from "@opengeni/contracts"; import { type Database } from "./database.js"; /** No cache: changes made with `bun run plans:catalog` are effective immediately. */ export declare function readSubscriptionPlanCatalog(db: Database): Promise<{ revision: number; plans: { key: string; label: string; stripePriceId: string | null; legacyStripePriceIds?: string[] | undefined; monthlyPriceMicros: number | null; monthlyCreditMicros: number; seatLimit: number | null; freeCredit: boolean; }[]; }>; export type OrganizationPlanStateInput = { accountId: string; planKey: string; status: "active" | "trialing" | "past_due" | "canceled" | "unpaid" | "paused" | "incomplete" | "incomplete_expired"; stripeSubscriptionId?: string | null; currentPeriodStart?: Date | null; currentPeriodEnd?: Date | null; cancelAtPeriodEnd?: boolean; }; export declare function upsertOrganizationPlan(db: Database, input: OrganizationPlanStateInput): Promise>; /** SQL receipt field names intentionally match the persisted periods table. */ export type PlanCreditPeriod = { id: string; account_id: string; plan_key: string; catalog_revision: number; stripe_subscription_id: string | null; period_start: string; period_end: string; granted_micros: number; opening_debt_micros: number; grant_entry_id: string; idempotency_key: string; granted_at: string; expired_at: string | null; expiry_entry_id: string | null; usage_at_expiry_micros: number | null; }; export type PlanCreditPeriodInput = { accountId: string; planKey: string; periodStart: Date; periodEnd: Date; stripeSubscriptionId?: string | null; }; /** One receipt per subscription/start/plan (Free: account/UTC month); changed terms fail. */ export declare const grantPlanCreditPeriod: (db: Database, input: PlanCreditPeriodInput) => Promise; /** Atomically expire the old allowance and grant a full new one. Replays never expire the new period. */ export declare const replacePlanCreditPeriod: (db: Database, input: PlanCreditPeriodInput) => Promise; export declare function expirePlanCreditPeriod(db: Database, input: { accountId: string; periodId: string; force?: boolean; }): Promise; /** Called under the existing account lock before any new ledger settlement. */ export declare function expireEndedPlanCreditPeriods(db: Database, accountId: string): Promise; /** One post-lock cutoff for expiry, allocation and the resulting ledger entry. */ export declare function beginPlanCreditSettlement(db: Database, accountId: string): Promise; export declare function freePlanCreditEligible(db: Database, accountId: string): Promise; export declare function getOrganizationPlanBalance(db: Database, accountId: string): Promise; /** * The organization's plan and its catalog monthly price: `null` for a * custom-priced plan (Enterprise) or a plan the catalog no longer lists. * Admission of the person's own subscriptions reads it. */ export declare function getOrganizationPlanStanding(db: Database, accountId: string): Promise<{ plan: BillingPlanBalance | null; monthlyPriceMicros: number | null; }>;