import { isAlphanumericWithSpace } from 'ontime-utils';

import { body, param } from 'express-validator';
import { requestValidationFunction } from '../validation-utils/validationFunction.js';

export const validateCustomField = [
  body('label')
    .isString()
    .trim()
    .notEmpty()
    .custom((value) => {
      return isAlphanumericWithSpace(value);
    }),
  body('type').isIn(['string', 'image']),
  body('colour').isString().trim(),

  requestValidationFunction,
];

export const validateEditCustomField = [
  param('key').isString().trim().notEmpty(),
  body('label')
    .isString()
    .trim()
    .notEmpty()
    .custom((value) => {
      return isAlphanumericWithSpace(value);
    }),
  body('type').isIn(['string', 'image']),
  body('colour').isString().trim(),

  requestValidationFunction,
];

export const validateDeleteCustomField = [param('key').isString().notEmpty(), requestValidationFunction];
