/**
 * Zod boundary schemas for the ticket API surface.
 * Shared client + server — import from feature components and from API routes.
 */

import { z } from 'zod';

export const newTicketSchema = z.object({
  category: z.enum(['account', 'billing', 'bug', 'how_to', 'complaint', 'other']),
  priority: z.enum(['low', 'normal', 'high', 'urgent']).optional().default('normal'),
  subject: z.string().min(3).max(200),
  body: z.string().min(10).max(5000),
  relatedPurchaseId: z.uuid().optional(),
  agentDefinitionSlug: z.string().max(100).optional(),
  attachmentIds: z.array(z.uuid()).max(10).optional().default([]),
});
export type NewTicketInput = z.infer<typeof newTicketSchema>;

export const listTicketsSchema = z.object({
  mine: z.coerce.boolean().optional().default(true),
  status: z
    .enum([
      'open',
      'ai_handling',
      'awaiting_user',
      'escalated',
      'awaiting_agent',
      'human_handling',
      'resolved',
      'closed',
      'reopened',
    ])
    .optional(),
  limit: z.coerce.number().int().min(1).max(50).optional().default(20),
  cursor: z.uuid().optional(),
});
export type ListTicketsInput = z.infer<typeof listTicketsSchema>;

export const newMessageSchema = z.object({
  body: z.string().min(1).max(5000),
  attachmentIds: z.array(z.uuid()).max(10).optional().default([]),
});
export type NewMessageInput = z.infer<typeof newMessageSchema>;
