"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 decimal_exports = {};
__export(decimal_exports, {
  CockroachDecimal: () => CockroachDecimal,
  CockroachDecimalBigInt: () => CockroachDecimalBigInt,
  CockroachDecimalBigIntBuilder: () => CockroachDecimalBigIntBuilder,
  CockroachDecimalBuilder: () => CockroachDecimalBuilder,
  CockroachDecimalNumber: () => CockroachDecimalNumber,
  CockroachDecimalNumberBuilder: () => CockroachDecimalNumberBuilder,
  decimal: () => decimal,
  numeric: () => numeric
});
module.exports = __toCommonJS(decimal_exports);
var import_entity = require("../../entity.cjs");
var import_utils = require("../../utils.cjs");
var import_common = require("./common.cjs");
class CockroachDecimalBuilder extends import_common.CockroachColumnWithArrayBuilder {
  static [import_entity.entityKind] = "CockroachDecimalBuilder";
  constructor(name, precision, scale) {
    super(name, "string", "CockroachDecimal");
    this.config.precision = precision;
    this.config.scale = scale;
  }
  /** @internal */
  build(table) {
    return new CockroachDecimal(
      table,
      this.config
    );
  }
}
class CockroachDecimal extends import_common.CockroachColumn {
  static [import_entity.entityKind] = "CockroachDecimal";
  precision;
  scale;
  constructor(table, config) {
    super(table, config);
    this.precision = config.precision;
    this.scale = config.scale;
  }
  mapFromDriverValue(value) {
    if (typeof value === "string") return value;
    return String(value);
  }
  getSQLType() {
    if (this.precision !== void 0 && this.scale !== void 0) {
      return `decimal(${this.precision}, ${this.scale})`;
    } else if (this.precision === void 0) {
      return "decimal";
    } else {
      return `decimal(${this.precision})`;
    }
  }
}
class CockroachDecimalNumberBuilder extends import_common.CockroachColumnWithArrayBuilder {
  static [import_entity.entityKind] = "CockroachDecimalNumberBuilder";
  constructor(name, precision, scale) {
    super(name, "number", "CockroachDecimalNumber");
    this.config.precision = precision;
    this.config.scale = scale;
  }
  /** @internal */
  build(table) {
    return new CockroachDecimalNumber(
      table,
      this.config
    );
  }
}
class CockroachDecimalNumber extends import_common.CockroachColumn {
  static [import_entity.entityKind] = "CockroachDecimalNumber";
  precision;
  scale;
  constructor(table, config) {
    super(table, config);
    this.precision = config.precision;
    this.scale = config.scale;
  }
  mapFromDriverValue(value) {
    if (typeof value === "number") return value;
    return Number(value);
  }
  mapToDriverValue = String;
  getSQLType() {
    if (this.precision !== void 0 && this.scale !== void 0) {
      return `decimal(${this.precision}, ${this.scale})`;
    } else if (this.precision === void 0) {
      return "decimal";
    } else {
      return `decimal(${this.precision})`;
    }
  }
}
class CockroachDecimalBigIntBuilder extends import_common.CockroachColumnWithArrayBuilder {
  static [import_entity.entityKind] = "CockroachDecimalBigIntBuilder";
  constructor(name, precision, scale) {
    super(name, "bigint", "CockroachDecimalBigInt");
    this.config.precision = precision;
    this.config.scale = scale;
  }
  /** @internal */
  build(table) {
    return new CockroachDecimalBigInt(
      table,
      this.config
    );
  }
}
class CockroachDecimalBigInt extends import_common.CockroachColumn {
  static [import_entity.entityKind] = "CockroachDecimalBigInt";
  precision;
  scale;
  constructor(table, config) {
    super(table, config);
    this.precision = config.precision;
    this.scale = config.scale;
  }
  mapFromDriverValue = BigInt;
  mapToDriverValue = String;
  getSQLType() {
    if (this.precision !== void 0 && this.scale !== void 0) {
      return `decimal(${this.precision}, ${this.scale})`;
    } else if (this.precision === void 0) {
      return "decimal";
    } else {
      return `decimal(${this.precision})`;
    }
  }
}
function decimal(a, b) {
  const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);
  const mode = config?.mode;
  return mode === "number" ? new CockroachDecimalNumberBuilder(name, config?.precision, config?.scale) : mode === "bigint" ? new CockroachDecimalBigIntBuilder(name, config?.precision, config?.scale) : new CockroachDecimalBuilder(name, config?.precision, config?.scale);
}
const numeric = decimal;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  CockroachDecimal,
  CockroachDecimalBigInt,
  CockroachDecimalBigIntBuilder,
  CockroachDecimalBuilder,
  CockroachDecimalNumber,
  CockroachDecimalNumberBuilder,
  decimal,
  numeric
});
//# sourceMappingURL=decimal.cjs.map