/**
 * Review domain effects — discriminated union.
 *
 * Effects are interpreted in order by apply-effects.ts.
 *
 * Ordering invariants:
 *   1. DB state writes (insert-review / update-review-reply / mark-removal-requested / insert-removal-queue)
 *   2. Vendor aggregate update (only for STANDARD reviews)
 *   3. Push notifications
 *   4. AI prescoring (fire-and-forget; never blocks)
 *
 * Pure module: no imports from @/server/db, do-client, outbox-producer, payments, fetch.
 */

export type InsertReviewEffect = {
  kind: 'insert-review';
  purchaseId: string;
  userId: string;
  vendorId: string;
  dealId: string;
  reviewType: 'STANDARD' | 'TECHNICAL';
  /** Required for STANDARD, undefined for TECHNICAL. */
  rating?: number;
  body: string;
};

export type UpdateVendorAggregateEffect = {
  kind: 'update-vendor-aggregate';
  vendorId: string;
  /** Rating from the new review. */
  rating: number;
};

export type SendVendorPushEffect = {
  kind: 'send-vendor-push';
  vendorId: string;
  rating: number;
  bodyPreview: string;
};

export type UpdateReviewReplyEffect = {
  kind: 'update-review-reply';
  reviewId: string;
  reply: string;
};

export type MarkRemovalRequestedEffect = {
  kind: 'mark-removal-requested';
  reviewId: string;
  reason: string;
};

export type InsertRemovalQueueEffect = {
  kind: 'insert-removal-queue';
  reviewId: string;
  submittedBy: string;
  reason: string;
};

export type EnqueueAiPrescoreEffect = {
  kind: 'enqueue-ai-prescore';
};

export type ReviewEffect =
  | InsertReviewEffect
  | UpdateVendorAggregateEffect
  | SendVendorPushEffect
  | UpdateReviewReplyEffect
  | MarkRemovalRequestedEffect
  | InsertRemovalQueueEffect
  | EnqueueAiPrescoreEffect;
