import { entityKind } from "../../entity.js";
import { getColumnNameAndConfig } from "../../utils.js";
import { CockroachColumn } from "./common.js";
import { CockroachDateColumnBaseBuilder } from "./date.common.js";
class CockroachTimestampBuilder extends CockroachDateColumnBaseBuilder {
  static [entityKind] = "CockroachTimestampBuilder";
  constructor(name, withTimezone, precision) {
    super(name, "date", "CockroachTimestamp");
    this.config.withTimezone = withTimezone;
    this.config.precision = precision;
  }
  /** @internal */
  build(table) {
    return new CockroachTimestamp(
      table,
      this.config
    );
  }
}
class CockroachTimestamp extends CockroachColumn {
  static [entityKind] = "CockroachTimestamp";
  withTimezone;
  precision;
  constructor(table, config) {
    super(table, config);
    this.withTimezone = config.withTimezone;
    this.precision = config.precision;
  }
  getSQLType() {
    const precision = this.precision === void 0 ? "" : ` (${this.precision})`;
    return `timestamp${precision}${this.withTimezone ? " with time zone" : ""}`;
  }
  mapFromDriverValue = (value) => {
    return new Date(this.withTimezone ? value : value + "+0000");
  };
  mapToDriverValue = (value) => {
    return value.toISOString();
  };
}
class CockroachTimestampStringBuilder extends CockroachDateColumnBaseBuilder {
  static [entityKind] = "CockroachTimestampStringBuilder";
  constructor(name, withTimezone, precision) {
    super(name, "string", "CockroachTimestampString");
    this.config.withTimezone = withTimezone;
    this.config.precision = precision;
  }
  /** @internal */
  build(table) {
    return new CockroachTimestampString(
      table,
      this.config
    );
  }
}
class CockroachTimestampString extends CockroachColumn {
  static [entityKind] = "CockroachTimestampString";
  withTimezone;
  precision;
  constructor(table, config) {
    super(table, config);
    this.withTimezone = config.withTimezone;
    this.precision = config.precision;
  }
  getSQLType() {
    const precision = this.precision === void 0 ? "" : `(${this.precision})`;
    return `timestamp${precision}${this.withTimezone ? " with time zone" : ""}`;
  }
}
function timestamp(a, b = {}) {
  const { name, config } = getColumnNameAndConfig(a, b);
  if (config?.mode === "string") {
    return new CockroachTimestampStringBuilder(name, config.withTimezone ?? false, config.precision);
  }
  return new CockroachTimestampBuilder(name, config?.withTimezone ?? false, config?.precision);
}
export {
  CockroachTimestamp,
  CockroachTimestampBuilder,
  CockroachTimestampString,
  CockroachTimestampStringBuilder,
  timestamp
};
//# sourceMappingURL=timestamp.js.map