import { ZodError } from "zod/v4";
import { ValidationErrorCollection, ValidationErrorDetail } from "../errors";

export function translateZodValidationError<T>(
  message: string,
  zodError: ZodError<T>,
  errorValue?: unknown
) {
  const errors: ValidationErrorDetail[] = [];
  for (const issue of zodError.issues) {
    errors.push({
      message: issue.message,
      path: issue.path.join("."),
      value: errorValue ?? issue.input,
    });
  }
  return new ValidationErrorCollection(message, errors);
}
