/**
 * Zod schemas for POST /api/admin/search.
 *
 * Validated at the API boundary (zod-at-boundary rule).
 * Both request and response are schema-validated.
 */

import { z } from 'zod';

// ─── Request ──────────────────────────────────────────────────────────────────

export const adminSearchRequestSchema = z.object({
  /** Search query string. Min 1 char, max 100. */
  q: z.string().min(1).max(100).trim(),
  /** Max results to return. Default 20, hard cap 20. */
  limit: z.number().int().min(1).max(20).default(20),
});

export type AdminSearchRequest = z.infer<typeof adminSearchRequestSchema>;

// ─── Response ─────────────────────────────────────────────────────────────────

export const adminSearchResultSchema = z.object({
  /** Entity type for icon/badge rendering. */
  type: z.enum(['route', 'vendor', 'user', 'deal', 'purchase']),
  /** Entity id (path for routes). */
  id: z.string(),
  /** Primary display text. */
  title: z.string(),
  /** Secondary display text (e.g. email, state). */
  subtitle: z.string().optional(),
  /** Navigation target. */
  href: z.string(),
});

export type AdminSearchResult = z.infer<typeof adminSearchResultSchema>;

export const adminSearchResponseSchema = z.object({
  ok: z.literal(true),
  results: z.array(adminSearchResultSchema),
  total: z.number(),
});

export type AdminSearchResponse = z.infer<typeof adminSearchResponseSchema>;
