import { Querier, Transaction } from "@platform-modules/db";
//#region src/errors.d.ts
declare class OversoldError extends Error {
  readonly skuId: string;
  readonly requested: number;
  readonly name = "OversoldError";
  readonly code: "OVERSOLD";
  constructor(skuId: string, requested: number);
}
declare class InventoryValidationError extends Error {
  readonly field: string;
  readonly name = "InventoryValidationError";
  readonly code: "INVENTORY_VALIDATION";
  constructor(field: string);
}
declare class InventoryItemNotFoundError extends Error {
  readonly skuId: string;
  readonly name = "InventoryItemNotFoundError";
  readonly code: "INVENTORY_ITEM_NOT_FOUND";
  constructor(skuId: string);
}
declare function isOversoldError(e: unknown): e is OversoldError;
declare function isInventoryValidationError(e: unknown): e is InventoryValidationError;
declare function isInventoryItemNotFoundError(e: unknown): e is InventoryItemNotFoundError;
//#endregion
//#region src/schema.d.ts
declare const inventoryItem: import("drizzle-orm/pg-core").PgTableWithColumns<{
  name: "inventory_item";
  schema: undefined;
  columns: {
    skuId: import("drizzle-orm/pg-core").PgColumn<{
      name: "sku_id";
      tableName: "inventory_item";
      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;
    }, {}, {}>;
    vendorId: import("drizzle-orm/pg-core").PgColumn<{
      name: "vendor_id";
      tableName: "inventory_item";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    quantityTotal: import("drizzle-orm/pg-core").PgColumn<{
      name: "quantity_total";
      tableName: "inventory_item";
      dataType: "number";
      columnType: "PgInteger";
      data: number;
      driverParam: string | number;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    quantitySold: import("drizzle-orm/pg-core").PgColumn<{
      name: "quantity_sold";
      tableName: "inventory_item";
      dataType: "number";
      columnType: "PgInteger";
      data: number;
      driverParam: string | number;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    createdAt: import("drizzle-orm/pg-core").PgColumn<{
      name: "created_at";
      tableName: "inventory_item";
      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;
    }, {}, {}>;
    updatedAt: import("drizzle-orm/pg-core").PgColumn<{
      name: "updated_at";
      tableName: "inventory_item";
      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 stockReservation: import("drizzle-orm/pg-core").PgTableWithColumns<{
  name: "stock_reservation";
  schema: undefined;
  columns: {
    id: import("drizzle-orm/pg-core").PgColumn<{
      name: "id";
      tableName: "stock_reservation";
      dataType: "string";
      columnType: "PgUUID";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: true;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    skuId: import("drizzle-orm/pg-core").PgColumn<{
      name: "sku_id";
      tableName: "stock_reservation";
      dataType: "string";
      columnType: "PgUUID";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    qty: import("drizzle-orm/pg-core").PgColumn<{
      name: "qty";
      tableName: "stock_reservation";
      dataType: "number";
      columnType: "PgInteger";
      data: number;
      driverParam: string | number;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    holderRef: import("drizzle-orm/pg-core").PgColumn<{
      name: "holder_ref";
      tableName: "stock_reservation";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    expiresAt: import("drizzle-orm/pg-core").PgColumn<{
      name: "expires_at";
      tableName: "stock_reservation";
      dataType: "date";
      columnType: "PgTimestamp";
      data: Date;
      driverParam: string;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    consumedAt: import("drizzle-orm/pg-core").PgColumn<{
      name: "consumed_at";
      tableName: "stock_reservation";
      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;
    }, {}, {}>;
    releasedAt: import("drizzle-orm/pg-core").PgColumn<{
      name: "released_at";
      tableName: "stock_reservation";
      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;
    }, {}, {}>;
    createdAt: import("drizzle-orm/pg-core").PgColumn<{
      name: "created_at";
      tableName: "stock_reservation";
      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 inventorySchema: {
  inventoryItem: import("drizzle-orm/pg-core").PgTableWithColumns<{
    name: "inventory_item";
    schema: undefined;
    columns: {
      skuId: import("drizzle-orm/pg-core").PgColumn<{
        name: "sku_id";
        tableName: "inventory_item";
        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;
      }, {}, {}>;
      vendorId: import("drizzle-orm/pg-core").PgColumn<{
        name: "vendor_id";
        tableName: "inventory_item";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      quantityTotal: import("drizzle-orm/pg-core").PgColumn<{
        name: "quantity_total";
        tableName: "inventory_item";
        dataType: "number";
        columnType: "PgInteger";
        data: number;
        driverParam: string | number;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      quantitySold: import("drizzle-orm/pg-core").PgColumn<{
        name: "quantity_sold";
        tableName: "inventory_item";
        dataType: "number";
        columnType: "PgInteger";
        data: number;
        driverParam: string | number;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      createdAt: import("drizzle-orm/pg-core").PgColumn<{
        name: "created_at";
        tableName: "inventory_item";
        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;
      }, {}, {}>;
      updatedAt: import("drizzle-orm/pg-core").PgColumn<{
        name: "updated_at";
        tableName: "inventory_item";
        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";
  }>;
  stockReservation: import("drizzle-orm/pg-core").PgTableWithColumns<{
    name: "stock_reservation";
    schema: undefined;
    columns: {
      id: import("drizzle-orm/pg-core").PgColumn<{
        name: "id";
        tableName: "stock_reservation";
        dataType: "string";
        columnType: "PgUUID";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: true;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      skuId: import("drizzle-orm/pg-core").PgColumn<{
        name: "sku_id";
        tableName: "stock_reservation";
        dataType: "string";
        columnType: "PgUUID";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      qty: import("drizzle-orm/pg-core").PgColumn<{
        name: "qty";
        tableName: "stock_reservation";
        dataType: "number";
        columnType: "PgInteger";
        data: number;
        driverParam: string | number;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      holderRef: import("drizzle-orm/pg-core").PgColumn<{
        name: "holder_ref";
        tableName: "stock_reservation";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      expiresAt: import("drizzle-orm/pg-core").PgColumn<{
        name: "expires_at";
        tableName: "stock_reservation";
        dataType: "date";
        columnType: "PgTimestamp";
        data: Date;
        driverParam: string;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      consumedAt: import("drizzle-orm/pg-core").PgColumn<{
        name: "consumed_at";
        tableName: "stock_reservation";
        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;
      }, {}, {}>;
      releasedAt: import("drizzle-orm/pg-core").PgColumn<{
        name: "released_at";
        tableName: "stock_reservation";
        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;
      }, {}, {}>;
      createdAt: import("drizzle-orm/pg-core").PgColumn<{
        name: "created_at";
        tableName: "stock_reservation";
        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 InventorySchema = typeof inventorySchema;
//#endregion
//#region src/migrate.d.ts
declare class InventoryMigrateError extends Error {
  readonly detail: string;
  readonly name = "InventoryMigrateError";
  readonly code: "INVENTORY_MIGRATE";
  constructor(detail: string);
}
declare function isInventoryMigrateError(e: unknown): e is InventoryMigrateError;
declare function pushSchema(db: Querier<InventorySchema>): Promise<void>;
//#endregion
//#region src/set-inventory.d.ts
declare function setInventory(tx: Transaction<InventorySchema>, item: {
  skuId: string;
  vendorId?: string | null;
  quantityTotal: number | null;
}): Promise<void>;
//#endregion
//#region src/types.d.ts
interface InventoryItem {
  skuId: string;
  vendorId: string | null;
  quantityTotal: number | null;
  quantitySold: number;
}
interface ReserveArgs {
  skuId: string;
  qty: number;
  holderRef: string;
  now: Date;
  ttlMs?: number;
}
//#endregion
//#region src/reserve.d.ts
declare function reserve(tx: Transaction<InventorySchema>, args: ReserveArgs): Promise<{
  reservationId: string;
}>;
//#endregion
//#region src/consume.d.ts
declare function consume(tx: Transaction<InventorySchema>, reservationId: string): Promise<boolean>;
//#endregion
//#region src/release.d.ts
declare function release(tx: Transaction<InventorySchema>, reservationId: string): Promise<void>;
//#endregion
//#region src/commit-stock.d.ts
declare function commitStock(tx: Transaction<InventorySchema>, skuId: string, qty: number): Promise<void>;
//#endregion
//#region src/get-availability.d.ts
declare function getAvailability(q: Querier<InventorySchema>, skuId: string): Promise<number | null>;
//#endregion
//#region src/sweep.d.ts
declare function sweepStaleReservations(q: Querier<InventorySchema>, now: Date): Promise<{
  released: number;
}>;
//#endregion
export { type InventoryItem, InventoryItemNotFoundError, InventoryMigrateError, type InventorySchema, InventoryValidationError, OversoldError, type ReserveArgs, commitStock, consume, getAvailability, inventoryItem, inventorySchema, isInventoryItemNotFoundError, isInventoryMigrateError, isInventoryValidationError, isOversoldError, pushSchema, release, reserve, setInventory, stockReservation, sweepStaleReservations };