"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, {
  MsSqlDecimal: () => MsSqlDecimal,
  MsSqlDecimalBigInt: () => MsSqlDecimalBigInt,
  MsSqlDecimalBigIntBuilder: () => MsSqlDecimalBigIntBuilder,
  MsSqlDecimalBuilder: () => MsSqlDecimalBuilder,
  MsSqlDecimalNumber: () => MsSqlDecimalNumber,
  MsSqlDecimalNumberBuilder: () => MsSqlDecimalNumberBuilder,
  decimal: () => decimal
});
module.exports = __toCommonJS(decimal_exports);
var import_entity = require("../../entity.cjs");
var import_utils = require("../../utils.cjs");
var import_common = require("./common.cjs");
class MsSqlDecimalBuilder extends import_common.MsSqlColumnBuilderWithIdentity {
  static [import_entity.entityKind] = "MsSqlDecimalBuilder";
  constructor(name, config) {
    super(name, "string", "MsSqlDecimal");
    this.config.precision = config?.precision;
    this.config.scale = config?.scale;
  }
  /** @internal */
  build(table) {
    return new MsSqlDecimal(
      table,
      this.config
    );
  }
}
class MsSqlDecimal extends import_common.MsSqlColumnWithIdentity {
  static [import_entity.entityKind] = "MsSqlDecimal";
  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 `decimal(${this.precision},${this.scale})`;
    } else if (this.precision === void 0) {
      return "decimal";
    } else {
      return `decimal(${this.precision})`;
    }
  }
}
class MsSqlDecimalNumberBuilder extends import_common.MsSqlColumnBuilderWithIdentity {
  static [import_entity.entityKind] = "MsSqlDecimalNumberBuilder";
  constructor(name, config) {
    super(name, "number", "MsSqlDecimalNumber");
    this.config.precision = config?.precision;
    this.config.scale = config?.scale;
  }
  /** @internal */
  build(table) {
    return new MsSqlDecimalNumber(
      table,
      this.config
    );
  }
}
class MsSqlDecimalNumber extends import_common.MsSqlColumnWithIdentity {
  static [import_entity.entityKind] = "MsSqlDecimalNumber";
  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 `decimal(${this.precision},${this.scale})`;
    } else if (this.precision === void 0) {
      return "decimal";
    } else {
      return `decimal(${this.precision})`;
    }
  }
}
class MsSqlDecimalBigIntBuilder extends import_common.MsSqlColumnBuilderWithIdentity {
  static [import_entity.entityKind] = "MsSqlDecimalBigIntBuilder";
  constructor(name, config) {
    super(name, "bigint", "MsSqlDecimalBigInt");
    this.config.precision = config?.precision ?? 18;
    this.config.scale = config?.scale ?? 0;
  }
  /** @internal */
  build(table) {
    return new MsSqlDecimalBigInt(
      table,
      this.config
    );
  }
}
class MsSqlDecimalBigInt extends import_common.MsSqlColumnWithIdentity {
  static [import_entity.entityKind] = "MsSqlDecimalBigInt";
  precision = this.config.precision;
  scale = this.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 MsSqlDecimalNumberBuilder(name, config) : mode === "bigint" ? new MsSqlDecimalBigIntBuilder(name, config) : new MsSqlDecimalBuilder(name, config);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  MsSqlDecimal,
  MsSqlDecimalBigInt,
  MsSqlDecimalBigIntBuilder,
  MsSqlDecimalBuilder,
  MsSqlDecimalNumber,
  MsSqlDecimalNumberBuilder,
  decimal
});
//# sourceMappingURL=decimal.cjs.map