"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var enum_exports = {};
__export(enum_exports, {
  CockroachEnumColumn: () => CockroachEnumColumn,
  CockroachEnumColumnBuilder: () => CockroachEnumColumnBuilder,
  CockroachEnumObjectColumn: () => CockroachEnumObjectColumn,
  CockroachEnumObjectColumnBuilder: () => CockroachEnumObjectColumnBuilder,
  cockroachEnum: () => cockroachEnum,
  cockroachEnumObjectWithSchema: () => cockroachEnumObjectWithSchema,
  cockroachEnumWithSchema: () => cockroachEnumWithSchema,
  isCockroachEnum: () => isCockroachEnum
});
module.exports = __toCommonJS(enum_exports);
var import_entity = require("../../entity.cjs");
var import_common = require("./common.cjs");
class CockroachEnumObjectColumnBuilder extends import_common.CockroachColumnWithArrayBuilder {
  static [import_entity.entityKind] = "CockroachEnumObjectColumnBuilder";
  constructor(name, enumInstance) {
    super(name, "string", "CockroachEnumObjectColumn");
    this.config.enum = enumInstance;
  }
  /** @internal */
  build(table) {
    return new CockroachEnumObjectColumn(
      table,
      this.config
    );
  }
}
class CockroachEnumObjectColumn extends import_common.CockroachColumn {
  static [import_entity.entityKind] = "CockroachEnumObjectColumn";
  enum;
  enumValues = this.config.enum.enumValues;
  constructor(table, config) {
    super(table, config);
    this.enum = config.enum;
  }
  getSQLType() {
    return this.enum.enumName;
  }
}
const isCockroachEnumSym = Symbol.for("drizzle:isCockroachEnum");
function isCockroachEnum(obj) {
  return !!obj && typeof obj === "function" && isCockroachEnumSym in obj && obj[isCockroachEnumSym] === true;
}
class CockroachEnumColumnBuilder extends import_common.CockroachColumnWithArrayBuilder {
  static [import_entity.entityKind] = "CockroachEnumColumnBuilder";
  constructor(name, enumInstance) {
    super(name, "string", "CockroachEnumColumn");
    this.config.enum = enumInstance;
  }
  /** @internal */
  build(table) {
    return new CockroachEnumColumn(
      table,
      this.config
    );
  }
}
class CockroachEnumColumn extends import_common.CockroachColumn {
  static [import_entity.entityKind] = "CockroachEnumColumn";
  enum = this.config.enum;
  enumValues = this.config.enum.enumValues;
  constructor(table, config) {
    super(table, config);
    this.enum = config.enum;
  }
  getSQLType() {
    return this.enum.enumName;
  }
}
function cockroachEnum(enumName, input) {
  return Array.isArray(input) ? cockroachEnumWithSchema(enumName, [...input], void 0) : cockroachEnumObjectWithSchema(enumName, input, void 0);
}
function cockroachEnumWithSchema(enumName, values, schema) {
  const enumInstance = Object.assign(
    (name) => new CockroachEnumColumnBuilder(name ?? "", enumInstance),
    {
      enumName,
      enumValues: values,
      schema,
      [isCockroachEnumSym]: true
    }
  );
  return enumInstance;
}
function cockroachEnumObjectWithSchema(enumName, values, schema) {
  const enumInstance = Object.assign(
    (name) => new CockroachEnumObjectColumnBuilder(name ?? "", enumInstance),
    {
      enumName,
      enumValues: Object.values(values),
      schema,
      [isCockroachEnumSym]: true
    }
  );
  return enumInstance;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  CockroachEnumColumn,
  CockroachEnumColumnBuilder,
  CockroachEnumObjectColumn,
  CockroachEnumObjectColumnBuilder,
  cockroachEnum,
  cockroachEnumObjectWithSchema,
  cockroachEnumWithSchema,
  isCockroachEnum
});
//# sourceMappingURL=enum.cjs.map