// src/types/express-custom.d.ts
import { RequestHandler, Request } from 'express';
import { z } from 'zod';

type ValidatedRequest<T extends z.ZodSchema> = Request<z.infer<T>['params'], any, z.infer<T>['body'], z.infer<T>['query']>;

/**
 * Defines a type-safe request handler that infers the types of
 * `req.body`, `req.query`, and `req.params` from a Zod schema.
 * This eliminates the need for type assertions in route handlers.
 */
export type ValidatedRequestHandler<T extends z.ZodSchema> = (
  req: ValidatedRequest<T>,
  res: Parameters<RequestHandler>[1],
  next: Parameters<RequestHandler>[2]
) => void | Promise<void>;