import { body, ValidationChain } from 'express-validator';
import { handleValidationErrors, strictBodyValidation, isNonNegativeNumber } from './common';

// Disclaimers - POST validation
export const validateCreateDisclaimer: ValidationChain[] = [
    body('title')
        .trim()
        .notEmpty().withMessage('Title is required'),
    body('content')
        .trim()
        .notEmpty().withMessage('Content is required'),
    body('image')
        .optional()
        .trim(),
    body('isActive')
        .optional()
        .isBoolean().withMessage('isActive must be a boolean value')
];

export const createDisclaimerValidation = [
    strictBodyValidation(['title', 'content', 'image', 'isActive']),
    ...validateCreateDisclaimer,
    handleValidationErrors
];

// Disclaimers - PUT validation
export const validateUpdateDisclaimer: ValidationChain[] = [
    body('title')
        .optional()
        .trim(),
    body('content')
        .optional()
        .trim(),
    body('image')
        .optional()
        .trim(),
    body('isActive')
        .optional()
        .isBoolean().withMessage('isActive must be a boolean value')
];

export const updateDisclaimerValidation = [
    strictBodyValidation(['title', 'content', 'image', 'isActive']),
    ...validateUpdateDisclaimer,
    handleValidationErrors
];

// How It Works Steps - POST validation
export const validateCreateHowItWorksStep: ValidationChain[] = [
    body('stepNumber')
        .notEmpty().withMessage('Step number is required')
        .isInt({ min: 1 }).withMessage('Step number must be a positive integer'),
    body('title')
        .trim()
        .notEmpty().withMessage('Title is required')
        ,
    body('description')
        .trim()
        .notEmpty().withMessage('Description is required'),
        
    body('icon')
        .optional()
        .trim()
      ,
    body('order')
        .optional()
        .custom(isNonNegativeNumber).withMessage('Order must be a non-negative number'),
    body('isActive')
        .optional()
        .isBoolean().withMessage('isActive must be a boolean value')
];

export const createHowItWorksStepValidation = [
    strictBodyValidation(['stepNumber', 'title', 'description', 'icon', 'order', 'isActive']),
    ...validateCreateHowItWorksStep,
    handleValidationErrors
];

// How It Works Steps - PUT validation
export const validateUpdateHowItWorksStep: ValidationChain[] = [
    body('stepNumber')
        .optional()
        .isInt({ min: 1 }).withMessage('Step number must be a positive integer'),
    body('title')
        .optional()
        .trim()
        ,
    body('description')
        .optional()
        .trim()
        ,
    body('icon')
        .optional()
        .trim()
        ,
    body('order')
        .optional()
        .custom(isNonNegativeNumber).withMessage('Order must be a non-negative number'),
    body('isActive')
        .optional()
        .isBoolean().withMessage('isActive must be a boolean value')
];

export const updateHowItWorksStepValidation = [
    strictBodyValidation(['stepNumber', 'title', 'description', 'icon', 'order', 'isActive']),
    ...validateUpdateHowItWorksStep,
    handleValidationErrors
];

// Testimonials - POST validation
export const validateCreateTestimonial: ValidationChain[] = [
    body('name')
        .trim()
        .notEmpty().withMessage('Name is required')
        ,
    body('designation')
        .trim()
        .notEmpty().withMessage('Designation is required')
        ,
    body('testimonial')
        .trim()
        .notEmpty().withMessage('Testimonial is required')
        ,
    body('userImage')
        .optional()
        .trim()
        ,
    body('backgroundImage')
        .optional()
        .trim()
        ,
    body('order')
        .optional()
        .custom(isNonNegativeNumber).withMessage('Order must be a non-negative number'),
    body('isActive')
        .optional()
        .isBoolean().withMessage('isActive must be a boolean value')
];

export const createTestimonialValidation = [
    strictBodyValidation(['name', 'designation', 'testimonial', 'userImage', 'backgroundImage', 'order', 'isActive']),
    ...validateCreateTestimonial,
    handleValidationErrors
];

// Testimonials - PUT validation
export const validateUpdateTestimonial: ValidationChain[] = [
    body('name')
        .optional()
        .trim()
        ,
    body('designation')
        .optional()
        .trim()
        ,
    body('testimonial')
        .optional()
        .trim()
       ,
    body('userImage')
        .optional()
        .trim()
       ,
    body('backgroundImage')
        .optional()
        .trim()
        ,
    body('order')
        .optional()
        .custom(isNonNegativeNumber).withMessage('Order must be a non-negative number'),
    body('isActive')
        .optional()
        .isBoolean().withMessage('isActive must be a boolean value')
];

export const updateTestimonialValidation = [
    strictBodyValidation(['name', 'designation', 'testimonial', 'userImage', 'backgroundImage', 'order', 'isActive']),
    ...validateUpdateTestimonial,
    handleValidationErrors
];

// Education Courses - POST validation
export const validateCreateEducationCourse: ValidationChain[] = [
    body('title')
        .trim()
        .notEmpty().withMessage('Title is required')
        ,
    body('subtitle')
        .trim()
        .notEmpty().withMessage('Subtitle is required')
        ,
    body('type')
        .trim()
        .notEmpty().withMessage('Type is required')
        ,
    body('duration')
        .trim()
        .notEmpty().withMessage('Duration is required')
       ,
    body('color')
        .trim()
        .notEmpty().withMessage('Color is required')
       ,
    body('icon')
        .optional()
        .trim()
       ,
    body('order')
        .optional()
        .custom(isNonNegativeNumber).withMessage('Order must be a non-negative number'),
    body('isActive')
        .optional()
        .isBoolean().withMessage('isActive must be a boolean value'),
    body('video')
        .optional()
        .trim()
        
];

export const createEducationCourseValidation = [
    strictBodyValidation(['title', 'subtitle', 'type', 'duration', 'color', 'icon', 'order', 'isActive', 'video']),
    ...validateCreateEducationCourse,
    handleValidationErrors
];

// Education Courses - PUT validation
export const validateUpdateEducationCourse: ValidationChain[] = [
    body('title')
        .optional()
        .trim()
       ,
    body('subtitle')
        .optional()
        .trim()
       ,
    body('type')
        .optional()
        .trim()
        ,
    body('duration')
        .optional()
        .trim()
        ,
    body('color')
        .optional()
        .trim()
        ,
    body('icon')
        .optional()
        .trim()
        ,
    body('order')
        .optional()
        .custom(isNonNegativeNumber).withMessage('Order must be a non-negative number'),
    body('isActive')
        .optional()
        .isBoolean().withMessage('isActive must be a boolean value'),
    body('video')
        .optional()
        .trim()
        
];

export const updateEducationCourseValidation = [
    strictBodyValidation(['title', 'subtitle', 'type', 'duration', 'color', 'icon', 'order', 'isActive', 'video']),
    ...validateUpdateEducationCourse,
    handleValidationErrors
];

// Return Expectations - POST validation
export const validateCreateReturnExpectation: ValidationChain[] = [
    body('title')
        .trim()
        .notEmpty().withMessage('Title is required')
      ,
    body('percentage')
        .trim()
        .notEmpty().withMessage('Percentage is required')
        .isLength({ max: 50 }).withMessage('Percentage must not exceed 50 characters'),
    body('description')
        .trim()
        .notEmpty().withMessage('Description is required')
       ,
    body('subDescription')
        .trim()
        .notEmpty().withMessage('Sub description is required')

];

export const createReturnExpectationValidation = [
    strictBodyValidation(['title', 'percentage', 'description', 'subDescription']),
    ...validateCreateReturnExpectation,
    handleValidationErrors
];

// Return Expectations - PUT validation
export const validateUpdateReturnExpectation: ValidationChain[] = [
    body('title')
        .optional()
        .trim()
       ,
    body('percentage')
        .optional()
        .trim()
        .isLength({ max: 50 }).withMessage('Percentage must not exceed 50 characters'),
    body('description')
        .optional()
        .trim()
        ,
    body('subDescription')
        .optional()
        .trim()

];

export const updateReturnExpectationValidation = [
    strictBodyValidation(['title', 'percentage', 'description', 'subDescription']),
    ...validateUpdateReturnExpectation,
    handleValidationErrors
];

// Demo Videos - POST validation
export const validateCreateDemoVideo: ValidationChain[] = [
    body('video')
        .trim()
        .notEmpty().withMessage('Video URL is required')
        
];

export const createDemoVideoValidation = [
    strictBodyValidation(['video']),
    ...validateCreateDemoVideo,
    handleValidationErrors
];

// Demo Videos - PUT validation
export const validateUpdateDemoVideo: ValidationChain[] = [
    body('video')
        .optional()
        .trim()
        
];

export const updateDemoVideoValidation = [
    strictBodyValidation(['video']),
    ...validateUpdateDemoVideo,
    handleValidationErrors
];
