import { ColumnBuilder } from "../../column-builder.js";
import { Column } from "../../column.js";
import { entityKind } from "../../entity.js";
import { ForeignKeyBuilder } from "../foreign-keys.js";
class MsSqlColumnBuilder extends ColumnBuilder {
  static [entityKind] = "MsSqlColumnBuilder";
  foreignKeyConfigs = [];
  references(ref, actions = {}) {
    this.foreignKeyConfigs.push({ ref, actions });
    return this;
  }
  unique(name) {
    this.config.isUnique = true;
    this.config.uniqueName = name;
    return this;
  }
  generatedAlwaysAs(as, config) {
    this.config.generated = {
      as,
      type: "always",
      mode: config?.mode ?? "virtual"
    };
    return this;
  }
  /** @internal */
  buildForeignKeys(column, table) {
    return this.foreignKeyConfigs.map(({ ref, actions }) => {
      return ((ref2, actions2) => {
        const builder = new ForeignKeyBuilder(() => {
          const foreignColumn = ref2();
          return { columns: [column], foreignColumns: [foreignColumn] };
        });
        if (actions2.onUpdate) {
          builder.onUpdate(actions2.onUpdate);
        }
        if (actions2.onDelete) {
          builder.onDelete(actions2.onDelete);
        }
        return builder.build(table);
      })(ref, actions);
    });
  }
}
class MsSqlColumn extends Column {
  constructor(table, config) {
    super(table, config);
    this.table = table;
  }
  static [entityKind] = "MsSqlColumn";
  /** @internal */
  shouldDisableInsert() {
    return false;
  }
}
class MsSqlColumnBuilderWithIdentity extends MsSqlColumnBuilder {
  static [entityKind] = "MsSqlColumnBuilderWithAutoIncrement";
  constructor(name, dataType, columnType) {
    super(name, dataType, columnType);
  }
  identity(config) {
    this.config.identity = {
      seed: config ? config.seed : 1,
      increment: config ? config.increment : 1
    };
    this.config.hasDefault = true;
    this.config.notNull = true;
    return this;
  }
}
class MsSqlColumnWithIdentity extends MsSqlColumn {
  static [entityKind] = "MsSqlColumnWithAutoIncrement";
  identity = this.config.identity;
  shouldDisableInsert() {
    return !!this.identity;
  }
}
export {
  MsSqlColumn,
  MsSqlColumnBuilder,
  MsSqlColumnBuilderWithIdentity,
  MsSqlColumnWithIdentity
};
//# sourceMappingURL=common.js.map