/**
 * CartCheckout domain effects — discriminated union.
 *
 * Pure module: no imports from @/server/db, do-client, outbox-producer, payments, fetch.
 *
 * Effect ordering in apply-effects.ts (canonical):
 *   1. reserve-line per OK line (DB insert purchases + decrement deal stock + outbox row)
 *   2. clear-cart (DB delete cart_items for user)
 *   3. enqueue-outbox per outbox row id (DB insert already happened in step 1)
 *
 * Reservation/QR generation and PENDING→COMPLETED finalization (which delegates
 * to the W1 purchase machine) happen in the orchestrator after applyEffects
 * returns the new purchase ids.
 */

import type { PromoClaim } from '@/server/promo/types.js';

export type CartCheckoutEffect =
  /** Insert PENDING purchase row + decrement SKU stock + refresh deal cache + insert outbox row. */
  | {
      kind: 'reserve-line';
      dealId: string;
      /** SKU whose stock to decrement. Null for legacy pre-variant cart items. */
      dealSkuId: string | null;
      vendorId: string;
      dealTitle: string;
      qty: number;
      amountPaid: string;
      commissionAmount: string;
      vendorAmount: string;
      expiresAt: Date;
      idempotencyKey: string;
      platformFeeAmountAgorot?: number;
      promoClaim?: PromoClaim;
    }
  /** Wipe cart_items for the user. */
  | {
      kind: 'clear-cart';
      userId: string;
    };
