import { OrderLine } from '@platform-modules/commerce-orders';
import { TransactionalDatabase, Querier } from '@platform-modules/db';
import { IntentStore, PaymentProvider, DedupStore } from '@platform-modules/billing';
import { FulfillmentPorts, FulfillmentNotification, StorageAdapter, FulfillmentDbSchema } from '@platform-modules/commerce-fulfillment';
import pg from 'pg';

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>;

export { type FakeFulfillmentPorts, type FakeFulfillmentPortsOptions, type FakeIntentStore, type FakePaymentProvider, type FakeProviderMode, type FakeStorageAdapter, type PgDedupStore, countAccessGrants, createFakeIntentStore, createFakePaymentProvider, createPgDedupStore, fakeFulfillmentPorts };
