const Joi = require('joi');

const blogSchema = Joi.object({
  slug: Joi.string().required(),
  title: Joi.string().required(),
  body: Joi.string().required(),
  categoryIDs: Joi.array().items(Joi.string()),
  tagIDs: Joi.array().items(Joi.string()),
  coverImage: Joi.string()
});

const validateBlog = (req, res, next) => {
  const { error } = blogSchema.validate(req.body);
  if (error) {
    return res.status(400).json({ error: error.details[0].message });
  }
  next();
};

module.exports = { validateBlog };