import { z } from "zod";

/**
 * Common Zod schemas used across API routes.
 */

/**
 * Schema for delete operations that take an ID.
 * Coerces string inputs to numbers.
 */
export const DeleteByIdSchema = z.object({
  id: z.coerce.number().int(),
});

/**
 * Schema for ID parameters (used in dynamic routes).
 */
export const IdParamSchema = z.object({
  id: z.coerce.number().int().positive(),
});

/**
 * Helper to parse and validate ID from route params.
 * Throws a Zod error if invalid, which gets caught by withErrorHandling.
 */
export async function parseIdParam(params: Promise<{ id: string }>): Promise<number> {
  const { id } = await params;
  return IdParamSchema.parse({ id }).id;
}


