import { p as v, v as h, b as g, c as y, a as k } from "../chunks/validators-BnLhuIhd.js";
import { j as I, a as S, g as T, c as q, h as F, f as _, i as A, e as R, d as L, b as D, n as x } from "../chunks/catalog-field-grounding-DoEBOXQd.js";
import { c as N, p as w, s as O, a as E, b as P } from "../chunks/source-identity-qAmkNtEK.js";
function d(e, a = {}) {
  const r = n(e), t = {
    connectionId: a.connectionId,
    connectionType: e,
    path: ["database", "schema", "table"],
    labels: {
      database: "Database",
      schema: "Schema",
      table: "Table"
    },
    prefixLevels: ["database", "schema", "table"],
    dialect: "postgres",
    supportsFilterClause: !0
  };
  return r.includes("postgres") ? {
    ...t,
    prefixLevels: ["schema", "table"],
    dialect: "postgres"
  } : r.includes("mysql") ? {
    ...t,
    prefixLevels: ["database", "table"],
    dialect: "mysql",
    supportsFilterClause: !1
  } : r.includes("mssql") || r.includes("sqlserver") ? {
    ...t,
    dialect: "mssql",
    supportsFilterClause: !1
  } : r.includes("redshift") ? {
    ...t,
    prefixLevels: ["schema", "table"],
    dialect: "redshift"
  } : r.includes("snowflake") ? {
    ...t,
    dialect: "snowflake"
  } : r.includes("clickhouse") ? {
    connectionId: a.connectionId,
    connectionType: e,
    path: ["database", "table"],
    labels: {
      database: "Database",
      table: "Table"
    },
    prefixLevels: ["database", "table"],
    dialect: "clickhouse",
    supportsFilterClause: !1
  } : r === "s3" || r === "api" ? {
    connectionId: a.connectionId,
    connectionType: e,
    path: ["table"],
    labels: {
      table: r === "api" ? "API Table" : "File Table"
    },
    prefixLevels: ["table"],
    dialect: "duckdb",
    supportsFilterClause: !0
  } : r === "googlesheets" || r === "fileupload" ? {
    connectionId: a.connectionId,
    connectionType: e,
    path: ["table"],
    labels: {
      table: "Table"
    },
    prefixLevels: ["table"],
    dialect: "postgres",
    supportsFilterClause: !0
  } : r === "s3tables" ? {
    ...t,
    labels: {
      database: "Database",
      schema: "Namespace",
      table: "Table"
    },
    dialect: "duckdb"
  } : r === "bigquery" ? {
    ...t,
    labels: {
      database: "Project",
      schema: "Dataset",
      table: "Table"
    },
    prefixLevels: ["schema", "table"],
    dialect: "bigquery",
    supportsFilterClause: !1
  } : t;
}
function c(e) {
  const a = n(e);
  switch (a) {
    case "mysql":
    case "bigquery":
    case "redshift":
    case "snowflake":
    case "clickhouse":
    case "duckdb":
    case "sqlite":
      return a;
    case "mssql":
    case "sqlserver":
      return "mssql";
    case "postgres":
    case "postgresql":
      return "postgres";
    default:
      return "unknown";
  }
}
function u(e) {
  return e.capabilities.prefixLevels.every(
    (a) => !!s(e.source, a)
  );
}
function m(e) {
  const a = e.quoteIdentifier ?? o;
  return e.capabilities.prefixLevels.map((r) => s(e.source, r)).filter((r) => !!r).map((r) => a(r, e.capabilities.dialect)).join(".");
}
function s(e, a) {
  return a === "database" ? e.databaseName : a === "schema" ? e.schemaName : e.tableName;
}
function o(e, a) {
  return a === "mysql" || a === "bigquery" || a === "clickhouse" || a === "duckdb" ? `\`${e.replace(/`/g, "``")}\`` : a === "mssql" ? `[${e.replace(/]/g, "]]")}]` : `"${e.replace(/"/g, '""')}"`;
}
function n(e) {
  if (typeof e != "string")
    return "";
  const a = [];
  for (const r of e.trim().toLowerCase())
    l(r) && a.push(r);
  return a.join("");
}
function l(e) {
  const a = e.charCodeAt(0);
  return a >= 48 && a <= 57 || a >= 97 && a <= 122;
}
const i = {
  kind: "semantic",
  domainId: "domain_sales",
  datasetName: "orders",
  connectionId: "conn_sales",
  label: "Orders"
}, p = {
  revenueKpi: {
    version: 1,
    kind: "metric",
    id: "revenue-kpi",
    label: "Revenue",
    source: i,
    metrics: [{ name: "revenue", role: "measure" }],
    primaryMetric: { name: "revenue", role: "measure" },
    comparison: { kind: "previous_period" },
    limit: 1
  },
  revenueTrend: {
    version: 1,
    kind: "records",
    id: "revenue-trend",
    label: "Revenue trend",
    source: i,
    fields: [
      { name: "order_date", role: "date", dataType: "date", label: "Order Date" },
      { name: "revenue", role: "measure", dataType: "number" }
    ],
    dateField: { name: "order_date", role: "date", dataType: "date" },
    timeGrain: "month",
    limit: 100
  },
  topCustomersRecords: {
    version: 1,
    kind: "records",
    id: "top-customers",
    label: "Top customers",
    source: i,
    fields: [
      { name: "customer_name", role: "dimension", dataType: "string" },
      { name: "segment", role: "dimension", dataType: "string" },
      { name: "revenue", role: "measure", dataType: "number" }
    ],
    orderBy: { field: { name: "revenue", role: "measure" }, direction: "desc" },
    limit: 20
  },
  regionInputOptions: {
    version: 1,
    kind: "inputOptions",
    id: "region-options",
    label: "Region options",
    source: i,
    field: { name: "region", role: "dimension", dataType: "string" },
    limit: 100
  },
  previousPeriodRevenueComparison: {
    version: 1,
    kind: "metric",
    id: "revenue-previous-period",
    label: "Revenue previous period comparison",
    source: i,
    metrics: [{ name: "revenue", role: "measure" }],
    primaryMetric: { name: "revenue", role: "measure" },
    dateField: { name: "order_date", role: "date", dataType: "date" },
    timeGrain: "week",
    comparison: { kind: "previous_period" },
    limit: 100
  },
  inboundSupplierConcentration: {
    version: 1,
    kind: "metric",
    id: "inbound-supplier-concentration",
    label: "Inbound supplier concentration",
    source: i,
    metrics: [
      { name: "net_tons", role: "measure" },
      { name: "ticket_value", role: "measure" }
    ],
    primaryMetric: { name: "net_tons", role: "measure" },
    dateField: { name: "ticket_date", role: "date", dataType: "date" },
    timeWindow: { unit: "month", value: 6, anchor: "latest_available" },
    dimensions: [{ name: "supplier_id", role: "dimension", dataType: "number" }],
    filters: [
      {
        field: { name: "direction", role: "dimension", dataType: "string" },
        operator: "=",
        values: ["Inbound"]
      }
    ],
    limit: 15
  },
  boundedSqlRanking: {
    version: 1,
    kind: "sql",
    id: "top-customer-ranking-sql",
    label: "Top customer ranking SQL",
    source: {
      kind: "sql",
      connectionId: "conn_sales",
      dialect: "postgres"
    },
    sql: "SELECT customer_name, SUM(revenue) AS revenue FROM public.orders GROUP BY customer_name ORDER BY revenue DESC LIMIT 20",
    limit: 20,
    rationale: "Ranking is SQL-natural because it requires ordering grouped aggregate rows.",
    fields: [
      { name: "customer_name", role: "dimension", dataType: "string" },
      { name: "revenue", role: "measure", dataType: "number" }
    ]
  }
};
export {
  p as SEMAPHOR_ANALYTICS_INTENT_FIXTURES,
  I as buildAnalyticsCatalogFieldSummary,
  m as buildSemaphorQualifiedSourcePath,
  S as getAnalyticsCatalogFieldCandidates,
  T as getAnalyticsCatalogFieldName,
  d as getSemaphorConnectionCapabilities,
  q as isAnalyticsCatalogDateField,
  F as isAnalyticsCatalogDimensionField,
  _ as isAnalyticsCatalogMetricField,
  A as isAnalyticsDateLikeDataType,
  R as isAnalyticsMetricIdentifierField,
  L as isAnalyticsTechnicalIdentifierField,
  D as normalizeAnalyticsCatalogDataType,
  x as normalizeAnalyticsCatalogName,
  c as normalizeSemaphorDialect,
  v as parseSemaphorIsoTimeWindowBoundary,
  N as preferSemaphorFieldRefMetadata,
  w as preferSemaphorSourceMetadata,
  O as semaphorFieldRefsMatch,
  u as semaphorSourceHasRequiredCoordinates,
  E as semaphorSourceIdentityKey,
  P as semaphorSourcesReferToSameDataset,
  h as validateSemaphorAnalyticsIntent,
  g as validateSemaphorAnalyticsRecoveryPlan,
  y as validateSemaphorDashboardIntent,
  k as validateSemaphorOperationIntent
};
