import { NextFunction, Request, Response } from "express";
import { CatchAsyncError } from "../../middleware/Catch";
import { z } from "zod";
import ZodValidation from "../../utils/zodValidator";

export const shopifyValidation = CatchAsyncError(async (req: Request, res: Response, next: NextFunction) => {

    const zodValidation = z.object({
        name: z
            .string({ message: "Please enter a valid name." })
            .trim()
            .min(4, { message: "Name must be at least 4 characters." })
            .max(50, { message: "Name must be at most 50 characters." })
            .regex(/^[a-zA-Z\s.'-]+$/, {
                message: "Name must contain only letters, spaces, apostrophes, and hyphens.",
            })
            .refine(name => name === name.trim(), {
                message: "Name must not contain leading or trailing whitespace.",
            }),

        shopifyId: z
            .string({ message: "Please enter a valid Shopify ID." })
            .min(6, { message: "Shopify ID must be at least 6 characters." })
            .max(50, { message: "Shopify ID must be at most 50 characters." })
            .regex(/^[a-zA-Z0-9-]+$/, {
                message: "Shopify ID must contain only alphanumeric characters and hyphens.",
            })

    })


    await ZodValidation(req, res, next, zodValidation)

})