import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
export { V as VestingInvariantError, i as isVestingInvariantError } from './errors-62gll_WB.js';
import { Transaction, Querier } from '@platform-modules/db';

/** 1:1 opt-in extension of ledgerEntries (entryId → ledgerEntries.id; cross-package, no drizzle relation). */
declare const ledgerEntryVesting: drizzle_orm_pg_core.PgTableWithColumns<{
    name: "ledger_entry_vesting";
    schema: undefined;
    columns: {
        entryId: drizzle_orm_pg_core.PgColumn<{
            name: "entry_id";
            tableName: "ledger_entry_vesting";
            dataType: "string";
            columnType: "PgUUID";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: true;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        matureAt: drizzle_orm_pg_core.PgColumn<{
            name: "mature_at";
            tableName: "ledger_entry_vesting";
            dataType: "date";
            columnType: "PgTimestamp";
            data: Date;
            driverParam: string;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        sweptAt: drizzle_orm_pg_core.PgColumn<{
            name: "swept_at";
            tableName: "ledger_entry_vesting";
            dataType: "date";
            columnType: "PgTimestamp";
            data: Date;
            driverParam: string;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        withdrawableAt: drizzle_orm_pg_core.PgColumn<{
            name: "withdrawable_at";
            tableName: "ledger_entry_vesting";
            dataType: "date";
            columnType: "PgTimestamp";
            data: Date;
            driverParam: string;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
    };
    dialect: "pg";
}>;
/** 1:1 opt-in extension of walletBalances (ownerId logical-maps to walletBalances.ownerId — NO cross-package FK; plain text PK). */
declare const walletVesting: drizzle_orm_pg_core.PgTableWithColumns<{
    name: "wallet_vesting";
    schema: undefined;
    columns: {
        ownerId: drizzle_orm_pg_core.PgColumn<{
            name: "owner_id";
            tableName: "wallet_vesting";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: true;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        pendingMinor: drizzle_orm_pg_core.PgColumn<{
            name: "pending_minor";
            tableName: "wallet_vesting";
            dataType: "bigint";
            columnType: "PgBigInt64";
            data: bigint;
            driverParam: string;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        maturedMinor: drizzle_orm_pg_core.PgColumn<{
            name: "matured_minor";
            tableName: "wallet_vesting";
            dataType: "bigint";
            columnType: "PgBigInt64";
            data: bigint;
            driverParam: string;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        carriedDebtMinor: drizzle_orm_pg_core.PgColumn<{
            name: "carried_debt_minor";
            tableName: "wallet_vesting";
            dataType: "bigint";
            columnType: "PgBigInt64";
            data: bigint;
            driverParam: string;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        withdrawableMinor: drizzle_orm_pg_core.PgColumn<{
            name: "withdrawable_minor";
            tableName: "wallet_vesting";
            dataType: "bigint";
            columnType: "PgBigInt64";
            data: bigint;
            driverParam: string;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        lifetimeEarnedMinor: drizzle_orm_pg_core.PgColumn<{
            name: "lifetime_earned_minor";
            tableName: "wallet_vesting";
            dataType: "bigint";
            columnType: "PgBigInt64";
            data: bigint;
            driverParam: string;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        updatedAt: drizzle_orm_pg_core.PgColumn<{
            name: "updated_at";
            tableName: "wallet_vesting";
            dataType: "date";
            columnType: "PgTimestamp";
            data: Date;
            driverParam: string;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
    };
    dialect: "pg";
}>;
declare const vestingSchema: {
    ledgerEntryVesting: drizzle_orm_pg_core.PgTableWithColumns<{
        name: "ledger_entry_vesting";
        schema: undefined;
        columns: {
            entryId: drizzle_orm_pg_core.PgColumn<{
                name: "entry_id";
                tableName: "ledger_entry_vesting";
                dataType: "string";
                columnType: "PgUUID";
                data: string;
                driverParam: string;
                notNull: true;
                hasDefault: false;
                isPrimaryKey: true;
                isAutoincrement: false;
                hasRuntimeDefault: false;
                enumValues: undefined;
                baseColumn: never;
                identity: undefined;
                generated: undefined;
            }, {}, {}>;
            matureAt: drizzle_orm_pg_core.PgColumn<{
                name: "mature_at";
                tableName: "ledger_entry_vesting";
                dataType: "date";
                columnType: "PgTimestamp";
                data: Date;
                driverParam: string;
                notNull: false;
                hasDefault: false;
                isPrimaryKey: false;
                isAutoincrement: false;
                hasRuntimeDefault: false;
                enumValues: undefined;
                baseColumn: never;
                identity: undefined;
                generated: undefined;
            }, {}, {}>;
            sweptAt: drizzle_orm_pg_core.PgColumn<{
                name: "swept_at";
                tableName: "ledger_entry_vesting";
                dataType: "date";
                columnType: "PgTimestamp";
                data: Date;
                driverParam: string;
                notNull: false;
                hasDefault: false;
                isPrimaryKey: false;
                isAutoincrement: false;
                hasRuntimeDefault: false;
                enumValues: undefined;
                baseColumn: never;
                identity: undefined;
                generated: undefined;
            }, {}, {}>;
            withdrawableAt: drizzle_orm_pg_core.PgColumn<{
                name: "withdrawable_at";
                tableName: "ledger_entry_vesting";
                dataType: "date";
                columnType: "PgTimestamp";
                data: Date;
                driverParam: string;
                notNull: false;
                hasDefault: false;
                isPrimaryKey: false;
                isAutoincrement: false;
                hasRuntimeDefault: false;
                enumValues: undefined;
                baseColumn: never;
                identity: undefined;
                generated: undefined;
            }, {}, {}>;
        };
        dialect: "pg";
    }>;
    walletVesting: drizzle_orm_pg_core.PgTableWithColumns<{
        name: "wallet_vesting";
        schema: undefined;
        columns: {
            ownerId: drizzle_orm_pg_core.PgColumn<{
                name: "owner_id";
                tableName: "wallet_vesting";
                dataType: "string";
                columnType: "PgText";
                data: string;
                driverParam: string;
                notNull: true;
                hasDefault: false;
                isPrimaryKey: true;
                isAutoincrement: false;
                hasRuntimeDefault: false;
                enumValues: [string, ...string[]];
                baseColumn: never;
                identity: undefined;
                generated: undefined;
            }, {}, {}>;
            pendingMinor: drizzle_orm_pg_core.PgColumn<{
                name: "pending_minor";
                tableName: "wallet_vesting";
                dataType: "bigint";
                columnType: "PgBigInt64";
                data: bigint;
                driverParam: string;
                notNull: true;
                hasDefault: true;
                isPrimaryKey: false;
                isAutoincrement: false;
                hasRuntimeDefault: false;
                enumValues: undefined;
                baseColumn: never;
                identity: undefined;
                generated: undefined;
            }, {}, {}>;
            maturedMinor: drizzle_orm_pg_core.PgColumn<{
                name: "matured_minor";
                tableName: "wallet_vesting";
                dataType: "bigint";
                columnType: "PgBigInt64";
                data: bigint;
                driverParam: string;
                notNull: true;
                hasDefault: true;
                isPrimaryKey: false;
                isAutoincrement: false;
                hasRuntimeDefault: false;
                enumValues: undefined;
                baseColumn: never;
                identity: undefined;
                generated: undefined;
            }, {}, {}>;
            carriedDebtMinor: drizzle_orm_pg_core.PgColumn<{
                name: "carried_debt_minor";
                tableName: "wallet_vesting";
                dataType: "bigint";
                columnType: "PgBigInt64";
                data: bigint;
                driverParam: string;
                notNull: true;
                hasDefault: true;
                isPrimaryKey: false;
                isAutoincrement: false;
                hasRuntimeDefault: false;
                enumValues: undefined;
                baseColumn: never;
                identity: undefined;
                generated: undefined;
            }, {}, {}>;
            withdrawableMinor: drizzle_orm_pg_core.PgColumn<{
                name: "withdrawable_minor";
                tableName: "wallet_vesting";
                dataType: "bigint";
                columnType: "PgBigInt64";
                data: bigint;
                driverParam: string;
                notNull: true;
                hasDefault: true;
                isPrimaryKey: false;
                isAutoincrement: false;
                hasRuntimeDefault: false;
                enumValues: undefined;
                baseColumn: never;
                identity: undefined;
                generated: undefined;
            }, {}, {}>;
            lifetimeEarnedMinor: drizzle_orm_pg_core.PgColumn<{
                name: "lifetime_earned_minor";
                tableName: "wallet_vesting";
                dataType: "bigint";
                columnType: "PgBigInt64";
                data: bigint;
                driverParam: string;
                notNull: true;
                hasDefault: true;
                isPrimaryKey: false;
                isAutoincrement: false;
                hasRuntimeDefault: false;
                enumValues: undefined;
                baseColumn: never;
                identity: undefined;
                generated: undefined;
            }, {}, {}>;
            updatedAt: drizzle_orm_pg_core.PgColumn<{
                name: "updated_at";
                tableName: "wallet_vesting";
                dataType: "date";
                columnType: "PgTimestamp";
                data: Date;
                driverParam: string;
                notNull: true;
                hasDefault: true;
                isPrimaryKey: false;
                isAutoincrement: false;
                hasRuntimeDefault: false;
                enumValues: undefined;
                baseColumn: never;
                identity: undefined;
                generated: undefined;
            }, {}, {}>;
        };
        dialect: "pg";
    }>;
};
type VestingSchema = typeof vestingSchema;
type LedgerEntryVesting = typeof ledgerEntryVesting.$inferSelect;
type WalletVesting = typeof walletVesting.$inferSelect;

/**
 * `@platform-modules/ledger/vesting` — opt-in vesting and carried-debt projection.
 */

declare function accrueVesting<S extends VestingSchema>(tx: Transaction<S>, input: {
    ownerId: string;
    entryId: string;
    amountMinor: bigint;
    matureAt: Date;
}): Promise<{
    state: 'pending' | 'matured';
}>;
declare function promoteEntries<S extends VestingSchema>(tx: Transaction<S>, input: {
    earnEntryIds: {
        entryId: string;
        ownerId: string;
    }[];
    perOwnerDeltas: {
        ownerId: string;
        deltaMinor: bigint;
    }[];
}): Promise<void>;
declare function settleClawback<S extends VestingSchema>(tx: Transaction<S>, input: {
    ownerId: string;
    amountMinor: bigint;
}): Promise<void>;
/**
 * Recomputes `withdrawableMinor` as max(0, eligible − paid) under the wallet_vesting owner lock.
 *
 * LOCK-THEN-COMPUTE (P5): upsert-then-lock the owner row FIRST, then call `compute()` so the
 * caller reads eligible/paid under the held lock, then write the clamped withdrawable.
 *
 * DEADLOCK-AVOIDANCE: `compute()` MUST read matured `ledger_entry_vesting` rows PLAIN — never
 * FOR UPDATE. Locking entry rows while holding the owner lock reverses lock order vs
 * `promoteEntries`' sweep (entry→owner) and deadlocks. The owner lock alone serializes
 * recompute against the T12 withdrawal debit (which locks the SAME wallet_vesting row first).
 */
declare function recomputeWithdrawable<S extends VestingSchema>(tx: Transaction<S>, target: {
    ownerId: string;
}, compute: () => Promise<{
    eligibleMinor: bigint;
    paidMinor: bigint;
}>): Promise<void>;
declare function setEntryWithdrawableAt<S extends VestingSchema>(tx: Transaction<S>, input: {
    entryId: string;
    withdrawableAt: Date | null;
}): Promise<void>;
declare function getVesting<S extends VestingSchema>(tx: Querier<S>, ownerId: string): Promise<{
    pendingMinor: bigint;
    maturedMinor: bigint;
    carriedDebtMinor: bigint;
    netMinor: bigint;
    withdrawableMinor: bigint;
    lifetimeEarnedMinor: bigint;
}>;

export { type LedgerEntryVesting, type VestingSchema, type WalletVesting, accrueVesting, getVesting, ledgerEntryVesting, promoteEntries, recomputeWithdrawable, setEntryWithdrawableAt, settleClawback, vestingSchema, walletVesting };
