import { z } from "zod/v4";
import { MetadataSchema } from "./metadata.dto";

/**
 * Crea un esquema Zod que representa un resultado ListViewDTO genérico.
 *
 * @param itemSchema Esquema Zod del elemento T
 * @returns Zod schema para ListViewDTO<T>
 */
export const PaginationSchema = z.object({
  page: z.number().int().min(1, "Page must be a positive integer"),
  per_page: z.number().int().min(1, "Items per page must be a positive integer"),
  total_pages: z.number().int().min(0, "Total pages must be a non-negative integer"),
  total_items: z.number().int().min(0, "Total items must be a non-negative integer"),
});

export type Pagination = z.infer<typeof PaginationSchema>;

export const createPaginatedListSchema = <T extends z.ZodTypeAny>(itemSchema: T) =>
  PaginationSchema.extend({
    items: z.array(itemSchema),
    metadata: MetadataSchema.optional(),
  });
