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

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 payoutValidation = [
  body("amount").isFloat({ gt: 0 }).withMessage("Amount must be a positive number"),
  body("accountNumber").isLength({ min: 10, max: 10 }).isNumeric().withMessage("Valid 10-digit account number required"),
  body("bankCode").notEmpty().withMessage("Bank code is required"),
  validateRequest,
];

export const customerCreationValidation = [
  body("fullName").notEmpty().trim().withMessage("Full name is required"),
  body("email").isEmail().withMessage("Valid customer email is required"),
  body("phoneNumber").optional().isMobilePhone().withMessage("Valid phone number required"),
  validateRequest,
];

export const feeUpdateValidation = [
    body("depositFeePercent").optional().isFloat({ min: 0, max: 100 }),
    body("depositFeeCap").optional().isFloat({ min: 0 }),
    body("payoutFeeFlat").optional().isFloat({ min: 0 }),
    validateRequest,
];

export const bvnKycValidation = [
  body("bvn").isLength({ min: 11, max: 11 }).isNumeric().withMessage("Valid 11-digit BVN is required"),
  validateRequest,
];

export const idKycValidation = [
  body("idType").toLowerCase().isIn(["nin"]).withMessage("Only NIN is currently supported for ID verification"),
  body("idValue").notEmpty().trim().withMessage("ID value is required"),
  validateRequest,
];

export const walletSwapValidation = [
  body("baseCurrency").notEmpty().isLength({ min: 3, max: 10 }).withMessage("baseCurrency is required"),
  body("targetCurrency").notEmpty().isLength({ min: 3, max: 10 }).withMessage("targetCurrency is required"),
  body("amount").isFloat({ gt: 0 }).withMessage("Amount must be a positive number"),
  validateRequest,
];
