/**
 * Zod schemas for the transaction-case API surface.
 * Shared client+server — safe to import in React components.
 */

import { z } from 'zod';

export const newCaseSchema = z.object({
  purchaseId: z.uuid(),
  category: z.enum([
    'item_not_as_described',
    'no_show_vendor',
    'quality_issue',
    'cannot_redeem',
    'cancellation_request',
    'fraud',
    'safety',
    'other',
  ]),
  customerAskOutcome: z.enum(['refund_full', 'refund_partial', 'replacement', 'deny']),
  customerAskAmountCents: z.number().int().nonnegative().nullable(),
  description: z.string().min(10).max(5000),
  escapeRequested: z.boolean().default(false),
});

export const listCasesSchema = z.object({
  role: z.enum(['customer', 'vendor']),
  status: z.string().optional(),
});

export const newMessageSchema = z.object({
  text: z.string().min(1).max(5000),
  visibility: z.enum(['public', 'vendor_internal']).default('public'),
  attachmentIds: z.array(z.uuid()).max(10).optional(),
});

export const vendorOfferSchema = z.object({
  outcome: z.enum(['refund_full', 'refund_partial', 'replacement', 'deny']),
  amountCents: z.number().int().positive().nullable(),
  reason: z.string().min(1).max(1000),
});

export const customerDecideSchema = z.object({
  offerId: z.uuid(),
  decision: z.enum(['accept', 'reject']),
});

export type NewCaseInput = z.infer<typeof newCaseSchema>;
export type ListCasesQuery = z.infer<typeof listCasesSchema>;
export type NewMessageInput = z.infer<typeof newMessageSchema>;
export type VendorOfferInput = z.infer<typeof vendorOfferSchema>;
export type CustomerDecideInput = z.infer<typeof customerDecideSchema>;
