import {
  BadRequestError
} from "./chunk-YCLRZPR6.js";
import {
  ZodError
} from "./chunk-5TQBOAE7.js";
import {
  require_source
} from "./chunk-M5OAS5QZ.js";
import {
  __toESM,
  init_cjs_shims
} from "./chunk-7GH3YGSC.js";

// src/utils/formatValidationErrors.ts
init_cjs_shims();
var import_chalk = __toESM(require_source(), 1);
var formatValidationErrors = (error) => {
  if (error instanceof BadRequestError) {
    return formatBadRequestError(error);
  }
  if (error instanceof ZodError) {
    return formatZodError(error);
  }
  if (error instanceof Error) {
    return {
      errors: [error.message],
      errorMessage: error.message
    };
  }
  return {
    errors: ["Unknown validation error"],
    errorMessage: "Unknown validation error"
  };
};
var formatBadRequestError = (error) => {
  const errorMessage = error.message;
  const errors = [];
  const schemaErrorPrefix = "Invalid schema provided:";
  if (errorMessage.includes(schemaErrorPrefix)) {
    const errorContent = errorMessage.substring(
      errorMessage.indexOf(schemaErrorPrefix) + schemaErrorPrefix.length
    );
    const individualErrors = errorContent.split(";").map((err) => err.trim()).filter((err) => err.length > 0);
    errors.push(...individualErrors);
  } else {
    errors.push(errorMessage);
  }
  return { errors, errorMessage };
};
var formatZodError = (error) => {
  const errors = error.errors.map((err) => {
    const path = err.path.join(".");
    return path ? `${path}: ${err.message}` : err.message;
  });
  return {
    errors,
    errorMessage: errors.join("; ")
  };
};
var logValidationErrors = (command, errors, headerMessage = "Validation issues:") => {
  command.logToStderr("\n" + import_chalk.default.yellow(headerMessage));
  errors.forEach((err, index) => {
    const prefix = import_chalk.default.gray(`  ${index + 1}.`);
    command.logToStderr(`${prefix} ${err}`);
  });
};

export {
  formatValidationErrors,
  logValidationErrors
};
