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

// uploadFileToS3 validation
export const validateUploadFileToS3: ValidationChain[] = [
    body('folder')
        .optional()
        .trim()
        .isLength({ max: 100 }).withMessage('Folder path must not exceed 100 characters')
        .matches(/^[a-zA-Z0-9_\-/]+$/).withMessage('Folder path can only contain alphanumeric characters, underscores, hyphens, and slashes')
];

export const uploadFileToS3Validation = [
    strictBodyValidation(['folder']),
    ...validateUploadFileToS3,
    handleValidationErrors
];

// uploadMultipleFilesToS3 validation
export const validateUploadMultipleFilesToS3: ValidationChain[] = [
    body('folder')
        .optional()
        .trim()
        .isLength({ max: 100 }).withMessage('Folder path must not exceed 100 characters')
        .matches(/^[a-zA-Z0-9_\-/]+$/).withMessage('Folder path can only contain alphanumeric characters, underscores, hyphens, and slashes')
];

export const uploadMultipleFilesToS3Validation = [
    strictBodyValidation(['folder']),
    ...validateUploadMultipleFilesToS3,
    handleValidationErrors
];

// deleteFileFromS3 validation
export const validateDeleteFileFromS3: ValidationChain[] = [
    body('key')
        .trim()
        .notEmpty().withMessage('File key is required')
        .isLength({ max: 500 }).withMessage('File key must not exceed 500 characters')
];

export const deleteFileFromS3Validation = [
    strictBodyValidation(['key']),
    ...validateDeleteFileFromS3,
    handleValidationErrors
];
