import { entityKind } from "../../entity.js";
import { getColumnNameAndConfig } from "../../utils.js";
import { MsSqlColumn } from "./common.js";
import { MsSqlDateColumnBaseBuilder } from "./date.common.js";
class MsSqlDateTime2Builder extends MsSqlDateColumnBaseBuilder {
  static [entityKind] = "MsSqlDateTime2Builder";
  constructor(name, config) {
    super(name, "date", "MsSqlDateTime2");
    this.config.precision = config?.precision;
  }
  /** @internal */
  build(table) {
    return new MsSqlDateTime2(
      table,
      this.config
    );
  }
}
class MsSqlDateTime2 extends MsSqlColumn {
  static [entityKind] = "MsSqlDateTime2";
  precision;
  constructor(table, config) {
    super(table, config);
    this.precision = config.precision;
  }
  getSQLType() {
    const precision = this.precision === void 0 ? "" : `(${this.precision})`;
    return `datetime2${precision}`;
  }
}
class MsSqlDateTime2StringBuilder extends MsSqlDateColumnBaseBuilder {
  static [entityKind] = "MsSqlDateTime2StringBuilder";
  constructor(name, config) {
    super(name, "string", "MsSqlDateTime2String");
    this.config.precision = config?.precision;
  }
  /** @internal */
  build(table) {
    return new MsSqlDateTime2String(
      table,
      this.config
    );
  }
}
class MsSqlDateTime2String extends MsSqlColumn {
  static [entityKind] = "MsSqlDateTime2String";
  precision;
  constructor(table, config) {
    super(table, config);
    this.precision = config.precision;
  }
  getSQLType() {
    const precision = this.precision === void 0 ? "" : `(${this.precision})`;
    return `datetime2${precision}`;
  }
  mapFromDriverValue(value) {
    return typeof value === "string" ? value : value?.toISOString() ?? null;
  }
}
function datetime2(a, b) {
  const { name, config } = getColumnNameAndConfig(a, b);
  if (config?.mode === "string") {
    return new MsSqlDateTime2StringBuilder(name, config);
  }
  return new MsSqlDateTime2Builder(name, config);
}
export {
  MsSqlDateTime2,
  MsSqlDateTime2Builder,
  MsSqlDateTime2String,
  MsSqlDateTime2StringBuilder,
  datetime2
};
//# sourceMappingURL=datetime2.js.map