import { PriceSnapshot, Cart } from '@platform-modules/commerce-cart';
import { ProductKind, OrdersSchema, Order } from '@platform-modules/commerce-orders';
import { FulfillmentPorts } from '@platform-modules/commerce-fulfillment';
import { SettleChargeDeps } from '@platform-modules/billing';
import { TransactionalDatabase, Transaction } from '@platform-modules/db';

type CheckoutInput = {
    cartId?: string;
    cart?: Cart;
    buyerRef: {
        userId: string;
    };
    priceMode: 'inclusive' | 'exclusive';
    currency: string;
    buyerCountry: string;
    idempotencyKey: string;
};
type CheckoutDeps<S extends OrdersSchema = OrdersSchema> = Omit<SettleChargeDeps<S>, 'db'> & {
    db: TransactionalDatabase<S>;
    fulfillment: FulfillmentPorts;
    onSettle?: (tx: Transaction<S>, order: Order) => Promise<void>;
};
type PricedLine = {
    variantId: string;
    qty: number;
    unitNet: bigint;
    vat: bigint;
    lineTotal: bigint;
};
type StaleSplit = {
    removed: string[];
    updated: {
        variantId: string;
        was: bigint;
        now: bigint;
    }[];
};
type CatalogEntry = {
    available: boolean;
    price: PriceSnapshot;
    kind: ProductKind;
    title?: string;
    /** Catalog product's vendorId — the authoritative source for money attribution (cart lines are client-shaped). */
    vendorId?: string | null;
};
/** Checkout-local catalog view — assembled in startCheckout from commerce-catalog reads. */
type CatalogSnapshot = ReadonlyMap<string, CatalogEntry>;

export type { CatalogSnapshot as C, PricedLine as P, StaleSplit as S, CheckoutDeps as a, CheckoutInput as b, CatalogEntry as c };
