/**
 * VendorDeal domain effects — discriminated union.
 *
 * The decider emits effects; apply-effects.ts interprets them.
 * Pure module: no imports from @/server/db, do-client, outbox-producer, payments, fetch.
 *
 * Effect ordering in apply-effects.ts (canonical):
 *   1. set-deal-state (DB update — dealState, contentHash, approvedAt/By)
 *   2. enqueue-llm-job (DB insert llm_jobs + queue send)
 *   3. arm-deal-alarm (idempotent CF-DO call)
 */

import type { DealState } from './events.js';

export type VendorDealEffect =
  /** Update deal row: state (+ optional contentHash / approvedAt / approvedBy). */
  | {
      kind: 'set-deal-state';
      dealId: string;
      nextState: DealState;
      contentHash?: string;
      approvedAt?: Date;
      approvedBy?: 'HUMAN' | 'AI_AGENT';
    }
  /** Insert llm_jobs row and send to LLM_JOBS_QUEUE. */
  | {
      kind: 'enqueue-llm-job';
      dealId: string;
      vendorId: string;
      inputs: {
        title: string;
        description: string;
        categoryId: string | null;
        dealType: string;
        originalPrice: string;
        discountedPrice: string;
        discountPercent: number;
        primaryImageKey: string | null;
      };
    }
  /** Arm the deal DO alarm at windowEnd. */
  | {
      kind: 'arm-deal-alarm';
      dealId: string;
      windowEnd: Date;
    };
