function c(n) {
  return typeof n == "string" ? n.trim().toLowerCase() : "";
}
function g(n) {
  return String(n.column_name || n.name || n.qualifiedFieldName || "");
}
function p(n) {
  return Array.from(
    new Set(
      [
        n.column_name,
        n.name,
        n.qualifiedFieldName,
        n.alias
      ].filter(
        (e) => typeof e == "string" && e.trim().length > 0
      ).map((e) => e.trim())
    )
  );
}
function o(n) {
  const e = C(n);
  return e ? e.includes("int") || e.includes("uint") || e.includes("bigint") || e.includes("smallint") || e.includes("tinyint") || e.includes("numeric") || e.includes("decimal") || e.includes("double") || e.includes("float") || e.includes("number") || e.includes("real") || e.includes("money") || e.includes("currency") || e.includes("percent") ? "number" : e.includes("timestamp") || e.includes("datetime") || e.startsWith("time") ? "datetime" : e.includes("date") ? "date" : e.includes("bool") ? "boolean" : "string" : "unknown";
}
function C(n) {
  let e = c(n), t = "";
  for (; e && e !== t; )
    t = e, e = d(e, "nullable"), e = d(e, "lowcardinality");
  return e;
}
function d(n, e) {
  const t = `${e}(`;
  return !n.startsWith(t) || !n.endsWith(")") ? n : n.slice(t.length, -1).trim();
}
function A(n) {
  const e = o(n);
  return e === "date" || e === "datetime";
}
function u(n) {
  return A(n.dataType || n.data_type);
}
function m(n) {
  const e = f(n);
  return e === "id" || e === "row_id";
}
function l(n) {
  const e = f(n);
  return m(n) || e.endsWith("_id") || e.endsWith("_key") || e.endsWith("_number");
}
function f(n) {
  return c(
    g(n) || n.name || n.alias
  ).replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
}
function y(n, e = {}) {
  const t = c(n.role);
  return t === "metric" || t === "measure" ? !e.excludeIdentifiers || !l(n) : t === "groupby" || t === "dimension" || t === "date" || t === "id" ? !1 : o(
    n.dataType || n.data_type
  ) === "number" && (!e.excludeIdentifiers || !l(n));
}
function h(n) {
  return !y(n) && !u(n);
}
function D(n) {
  const e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set();
  for (const a of n) {
    if (m(a))
      continue;
    const r = p(a);
    if (r.length !== 0) {
      if (u(a)) {
        r.forEach((i) => t.add(i));
        continue;
      }
      if (y(a, { excludeIdentifiers: !0 })) {
        r.forEach((i) => e.add(i));
        continue;
      }
      r.forEach((i) => s.add(i));
    }
  }
  return {
    validMetricCandidates: Array.from(e).sort(),
    validDateCandidates: Array.from(t).sort(),
    validDimensionCandidates: Array.from(s).sort()
  };
}
export {
  p as a,
  o as b,
  u as c,
  m as d,
  l as e,
  y as f,
  g,
  h,
  A as i,
  D as j,
  c as n
};
