import { body, param, validationResult } from 'express-validator';
import { updateProfileSchema, educationSchema, statusUpdateSchema, documentVerifySchema, chatSendSchema, settingsUpdateSchema, programSchema, announcementSchema, userCreateSchema, userUpdateSchema } from '../../domain/schemas';

export const validateUpdateProfile = [
  body().custom((val) => updateProfileSchema.parse(val)),
  (req, res, next) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) return res.status(400).json({ success: false, error: errors.array().map(e => e.msg) });
    next();
  },
];

export const validateEducation = [
  body().custom((val) => educationSchema.parse(val)),
  (req, res, next) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) return res.status(400).json({ success: false, error: errors.array().map(e => e.msg) });
    next();
  },
];

export const validateStatusUpdate = [
  body().custom((val) => statusUpdateSchema.parse(val)),
  (req, res, next) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) return res.status(400).json({ success: false, error: errors.array().map(e => e.msg) });
    next();
  },
];

export const validateDocumentVerify = [
  body().custom((val) => documentVerifySchema.parse(val)),
  (req, res, next) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) return res.status(400).json({ success: false, error: errors.array().map(e => e.msg) });
    next();
  },
];

export const validateChatSend = [
  body().custom((val) => chatSendSchema.parse(val)),
  (req, res, next) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) return res.status(400).json({ success: false, error: errors.array().map(e => e.msg) });
    next();
  },
];

export const validateSettings = [
  body().custom((val) => settingsUpdateSchema.parse(val)),
  (req, res, next) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) return res.status(400).json({ success: false, error: errors.array().map(e => e.msg) });
    next();
  },
];

export const validateProgram = [
  body().custom((val) => programSchema.parse(val)),
  (req, res, next) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) return res.status(400).json({ success: false, error: errors.array().map(e => e.msg) });
    next();
  },
];

export const validateAnnouncement = [
  body().custom((val) => announcementSchema.parse(val)),
  (req, res, next) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) return res.status(400).json({ success: false, error: errors.array().map(e => e.msg) });
    next();
  },
];

export const validateUserCreate = [
  body().custom((val) => userCreateSchema.parse(val)),
  (req, res, next) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) return res.status(400).json({ success: false, error: errors.array().map(e => e.msg) });
    next();
  },
];

export const validateUserUpdate = [
  body().custom((val) => userUpdateSchema.parse(val)),
  (req, res, next) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) return res.status(400).json({ success: false, error: errors.array().map(e => e.msg) });
    next();
  },
];
