import type { NextFunction, Request, Response } from "express";

export const asyncHandler =
  (handler: (request: Request, response: Response, next: NextFunction) => Promise<unknown>) =>
  (request: Request, response: Response, next: NextFunction) => {
    handler(request, response, next).catch(next);
  };

export const parseCsv = (value: unknown) => {
  if (typeof value !== "string" || value.trim() === "") {
    return [];
  }

  return value
    .split(",")
    .map((entry) => entry.trim())
    .filter(Boolean);
};

export const isDateString = (value: string) => /^\d{4}-\d{2}-\d{2}$/.test(value);
