function extractPathParams(path) {
  const params = [];
  const colonPattern = /:(\w+)/g;
  let match;
  while ((match = colonPattern.exec(path)) !== null) {
    params.push({
      name: match[1],
      pattern: match[0],
      value: "",
      required: true
    });
  }
  const bracketPattern = /\[([^\]]+)\]/g;
  while ((match = bracketPattern.exec(path)) !== null) {
    const paramName = match[1];
    const isCatchAll = paramName.startsWith("...");
    const isOptional = match[0].startsWith("[[");
    const cleanName = paramName.replace("...", "");
    params.push({
      name: cleanName,
      pattern: match[0],
      value: "",
      required: !isOptional && !isCatchAll
    });
  }
  return params;
}
function buildUrl(basePath, pathParams, queryParams) {
  let url = basePath;
  for (const param of pathParams) {
    if (param.value) {
      url = url.replace(param.pattern, param.value);
    }
  }
  const searchParams = new URLSearchParams();
  for (const qp of queryParams) {
    if (qp.enabled && qp.key && qp.value) {
      searchParams.append(qp.key, qp.value);
    }
  }
  const queryString = searchParams.toString();
  if (queryString) {
    url = `${url}?${queryString}`;
  }
  return url;
}
function validatePathParams(params) {
  const errors = [];
  for (const param of params) {
    if (param.required && !param.value) {
      errors.push(`Path parameter "${param.name}" is required`);
    }
  }
  return errors;
}
function validateJsonBody(body) {
  if (!body.trim()) return null;
  try {
    JSON.parse(body);
    return null;
  } catch {
    return "Invalid JSON format";
  }
}
export {
  buildUrl,
  extractPathParams,
  validateJsonBody,
  validatePathParams
};
