import { OrderLine } from "@platform-modules/commerce-orders";
import { DedupStore, IntentStore, PaymentProvider } from "@platform-modules/billing";
import { FulfillmentDbSchema, FulfillmentNotification, FulfillmentPorts, StorageAdapter } from "@platform-modules/commerce-fulfillment";
import { Querier, TransactionalDatabase } from "@platform-modules/db";
import pg from "pg";
//#region src/testing/index.d.ts
type FakeProviderMode = {
  kind: 'requires_client_action';
  clientSecret?: string;
  providerRef?: string;
} | {
  kind: 'settled';
  providerRef?: string;
} | {
  kind: 'throw';
  error?: unknown;
};
interface FakePaymentProvider extends PaymentProvider {
  readonly chargeCallCount: number;
  setMode(mode: FakeProviderMode): void;
}
declare function createFakePaymentProvider(initialMode?: FakeProviderMode): FakePaymentProvider;
type FakeIntent = {
  status: 'pending' | 'settled';
  providerRef?: string;
  amount: number;
  currency: string;
};
interface FakeIntentStore extends IntentStore {
  readonly intents: Map<string, FakeIntent>;
  readonly claims: string[];
  setClaimResult(chargeKey: string, result: 'won' | 'pending' | 'settled'): void;
}
declare function createFakeIntentStore(opts?: {
  forcePending?: boolean;
}): FakeIntentStore;
interface PgDedupStore extends DedupStore {
  readonly claims: string[];
  readonly marked: string[];
}
declare function createPgDedupStore(pool: pg.Pool): PgDedupStore;
interface FakeStorageAdapter extends StorageAdapter {
  readonly puts: Array<{
    key: string;
    body: Uint8Array | ArrayBuffer;
  }>;
}
interface FakeFulfillmentPortsOptions {
  db: TransactionalDatabase<FulfillmentDbSchema>;
  resolveBlobKey?: (line: OrderLine) => Promise<string>;
  notify?: (notification: FulfillmentNotification) => Promise<void>;
}
interface FakeFulfillmentPorts extends FulfillmentPorts {
  readonly notifications: FulfillmentNotification[];
  readonly storage: FakeStorageAdapter;
  setResolveBlobKey(fn: (line: OrderLine) => Promise<string>): void;
}
declare function fakeFulfillmentPorts(options: FakeFulfillmentPortsOptions): FakeFulfillmentPorts;
declare function countAccessGrants(db: Querier<FulfillmentDbSchema>, orderId: string): Promise<number>;
//#endregion
export { FakeFulfillmentPorts, FakeFulfillmentPortsOptions, FakeIntentStore, FakePaymentProvider, FakeProviderMode, FakeStorageAdapter, PgDedupStore, countAccessGrants, createFakeIntentStore, createFakePaymentProvider, createPgDedupStore, fakeFulfillmentPorts };