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