import { z } from "zod";
import { MongoCrudSchema } from "./mongo-crud";
import { paginatedRequestSchema } from "../types";

export const objectIdSchema = z.string();

export const crudSchema = <T extends z.ZodRawShape>(
  baseSchema: z.ZodObject<T>
): MongoCrudSchema => {
  const create = baseSchema;

  const get = paginatedRequestSchema.extend({
    _id: objectIdSchema.optional(),
  });

  const update = baseSchema.extend({
    _id: objectIdSchema,
  });

  const deleteSchema = z.object({
    _id: objectIdSchema,
  });

  return {
    create,
    get,
    update,
    delete: deleteSchema,
  };
};
