import { entityKind } from "../../entity.js";
import { CockroachColumn, CockroachColumnWithArrayBuilder } from "./common.js";
class CockroachEnumObjectColumnBuilder extends CockroachColumnWithArrayBuilder {
  static [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 CockroachColumn {
  static [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 CockroachColumnWithArrayBuilder {
  static [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 CockroachColumn {
  static [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;
}
export {
  CockroachEnumColumn,
  CockroachEnumColumnBuilder,
  CockroachEnumObjectColumn,
  CockroachEnumObjectColumnBuilder,
  cockroachEnum,
  cockroachEnumObjectWithSchema,
  cockroachEnumWithSchema,
  isCockroachEnum
};
//# sourceMappingURL=enum.js.map