/**
 * The public enquiry input schema is the frontend's, verbatim — re-exported from
 * the contract copy so there is one definition to keep in sync (PLANNING.md §9).
 * The admin list/reply/status schemas below are ours (PLANNING.md §4b).
 */
import { z } from 'zod';

export { enquiryInputSchema, type EnquiryInput } from '../../types/contract';

const STATUSES = ['new', 'read', 'replied', 'spam', 'archived'] as const;
const SOURCES = ['contact', 'genesis', 'hive', 'home'] as const;

/** GET /admin/enquiries query string. */
export const listQuerySchema = z.object({
  status: z.enum(STATUSES).optional(),
  source: z.enum(SOURCES).optional(),
  q: z.string().trim().min(1).max(100).optional(),
  from: z.string().trim().min(1).optional(), // YYYY-MM-DD or ISO datetime, treated as UTC
  to: z.string().trim().min(1).optional(),
  page: z.coerce.number().int().min(1).default(1),
  perPage: z.coerce.number().int().min(1).max(100).default(20),
  sort: z.enum(['newest', 'oldest']).default('newest'),
});

/** POST /admin/enquiries/:id/replies body. */
export const replySchema = z.object({
  body: z.string().trim().min(1).max(5000),
});

/** PATCH /admin/enquiries/:id body — `new` is not a settable value (§4b). */
export const statusPatchSchema = z.object({
  status: z.enum(['read', 'replied', 'spam', 'archived']),
});

export type ListQuery = z.infer<typeof listQuerySchema>;
export type ReplyInput = z.infer<typeof replySchema>;
export type StatusPatch = z.infer<typeof statusPatchSchema>;
