import { body, validationResult } from "express-validator";

export const validateRequest = (req, res, next) => {
  const errors = validationResult(req);
  if (!errors.isEmpty()) {
    return res.status(400).json({ success: false, errors: errors.array() });
  }
  next();
};

export const loginValidation = [
  body("email").isEmail().withMessage("Valid email is required"),
  body("password").notEmpty().withMessage("Password is required"),
  validateRequest,
];

export const merchantRegistrationValidation = [
  body("businessName").notEmpty().trim().withMessage("Business name is required"),
  body("email").isEmail().withMessage("Valid merchant email is required"),
  body("password").isLength({ min: 8 }).withMessage("Password must be at least 8 characters long"),
  validateRequest,
];
