const { body } = require('express-validator')

const validateName = [
  body('name')
    .trim()
    .notEmpty()
    .withMessage('Name is required')
    .isLength({ min: 2, max: 100 })
    .withMessage('Name must be between 2 and 100 characters')
]

const validateCode = [
  body('code')
    .optional()
    .trim()
    .isLength({ max: 10 })
    .withMessage('Code must not exceed 10 characters')
]

const validateId = (field) => [
  body(field)
    .notEmpty()
    .withMessage(`${field} is required`)
    .isInt({ min: 1 })
    .withMessage(`${field} must be a positive integer`)
]

const createCountryValidation = [
  ...validateName,
  ...validateCode
]

const updateCountryValidation = [
  ...validateName,
  ...validateCode
]

const createDivisionValidation = [
  ...validateId('country_id'),
  ...validateName,
  ...validateCode
]

const updateDivisionValidation = [
  ...validateName,
  ...validateCode
]

const createDistrictValidation = [
  ...validateId('division_id'),
  ...validateName,
  ...validateCode
]

const updateDistrictValidation = [
  ...validateName,
  ...validateCode
]

const createThanaValidation = [
  ...validateId('district_id'),
  ...validateName,
  ...validateCode
]

const updateThanaValidation = [
  ...validateName,
  ...validateCode
]

module.exports = {
  createCountryValidation,
  updateCountryValidation,
  createDivisionValidation,
  updateDivisionValidation,
  createDistrictValidation,
  updateDistrictValidation,
  createThanaValidation,
  updateThanaValidation
}
