import { entityKind } from "../entity.js";
import { Table } from "../table.js";
import { getCockroachColumnBuilders } from "./columns/all.js";
const InlineForeignKeys = Symbol.for("drizzle:CockroachInlineForeignKeys");
const EnableRLS = Symbol.for("drizzle:EnableRLS");
class CockroachTable extends Table {
  static [entityKind] = "CockroachTable";
  /** @internal */
  static Symbol = Object.assign({}, Table.Symbol, {
    InlineForeignKeys,
    EnableRLS
  });
  /**@internal */
  [InlineForeignKeys] = [];
  /** @internal */
  [EnableRLS] = false;
  /** @internal */
  [Table.Symbol.ExtraConfigBuilder] = void 0;
  /** @internal */
  [Table.Symbol.ExtraConfigColumns] = {};
}
function cockroachTableWithSchema(name, columns, extraConfig, schema, baseName = name) {
  const rawTable = new CockroachTable(name, schema, baseName);
  const parsedColumns = typeof columns === "function" ? columns(getCockroachColumnBuilders()) : columns;
  const builtColumns = Object.fromEntries(
    Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
      const colBuilder = colBuilderBase;
      colBuilder.setName(name2);
      const column = colBuilder.build(rawTable);
      rawTable[InlineForeignKeys].push(...colBuilder.buildForeignKeys(column, rawTable));
      return [name2, column];
    })
  );
  const builtColumnsForExtraConfig = Object.fromEntries(
    Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
      const colBuilder = colBuilderBase;
      colBuilder.setName(name2);
      const column = colBuilder.buildExtraConfigColumn(rawTable);
      return [name2, column];
    })
  );
  const table = Object.assign(rawTable, builtColumns);
  table[Table.Symbol.Columns] = builtColumns;
  table[Table.Symbol.ExtraConfigColumns] = builtColumnsForExtraConfig;
  if (extraConfig) {
    table[CockroachTable.Symbol.ExtraConfigBuilder] = extraConfig;
  }
  return Object.assign(table, {
    enableRLS: () => {
      table[CockroachTable.Symbol.EnableRLS] = true;
      return table;
    }
  });
}
const cockroachTable = (name, columns, extraConfig) => {
  return cockroachTableWithSchema(name, columns, extraConfig, void 0);
};
function cockroachTableCreator(customizeTableName) {
  return (name, columns, extraConfig) => {
    return cockroachTableWithSchema(customizeTableName(name), columns, extraConfig, void 0, name);
  };
}
export {
  CockroachTable,
  EnableRLS,
  InlineForeignKeys,
  cockroachTable,
  cockroachTableCreator,
  cockroachTableWithSchema
};
//# sourceMappingURL=table.js.map