import { AnyMsSqlColumn } from "../columns/common.cjs";
import { QueryBuilder } from "./query-builder.cjs";
import { SelectedFieldsFlat, SelectedFieldsOrdered } from "./select.types.cjs";
import { entityKind } from "../../entity.cjs";
import { TypedQueryBuilder } from "../../query-builders/query-builder.cjs";
import { SelectResultFields } from "../../query-builders/select.types.cjs";
import { Placeholder, Query, SQL, SQLWrapper } from "../../sql/sql.cjs";
import { InferInsertModel, InferSelectModel } from "../../table.cjs";
import { DrizzleTypeError } from "../../utils.cjs";
import { QueryPromise } from "../../query-promise.cjs";
import { MsSqlTable } from "../table.cjs";
import { MsSqlDialect } from "../dialect.cjs";
import { AnyQueryResultHKT, MsSqlSession, PreparedQueryConfig, PreparedQueryHKTBase, PreparedQueryKind, QueryResultHKT, QueryResultKind } from "../session.cjs";

//#region src/mssql-core/query-builders/insert.d.ts
interface MsSqlInsertConfig<TTable extends MsSqlTable = MsSqlTable> {
  table: TTable;
  values: Record<string, unknown>[] | TypedQueryBuilder<MsSqlInsertSelection<TTable>> | SQL;
  output?: SelectedFieldsOrdered;
  select?: boolean;
  columnList?: string[];
}
type MsSqlInsertValue<TTable extends MsSqlTable, TColumnsList extends string[] | 'all' = 'all', TModel extends Record<string, any> = InferInsertModel<TTable>> = { [K in keyof TModel as TColumnsList extends 'all' ? K : Extract<K, TColumnsList[number]>]: TModel[K] | SQL | Placeholder } & {};
type MsSqlInsertSelection<TTable extends MsSqlTable, TColumnsList extends string[] | 'all' = 'all', TModel extends Record<string, unknown> = InferInsertModel<TTable>> = { [K in keyof TModel as TColumnsList extends 'all' ? K : Extract<K, TColumnsList[number]>]: AnyMsSqlColumn | SQL | SQL.Aliased | TModel[K] } & {};
type ValidateInsertSelectionKey<TTable extends MsSqlTable, TSelection extends MsSqlInsertSelection<any>, K extends keyof TSelection> = K extends keyof InferInsertModel<TTable> ? TSelection[K] : DrizzleTypeError<`Column "${K & string}" does not exist in table "${TTable['_']['name']}"`>;
type NoUnknownKeysInInsertSelection<TTable extends MsSqlTable, TSelection extends MsSqlInsertSelection<any>, TColumnList extends string[] | 'all' = 'all'> = { [K in keyof TSelection]: TColumnList extends string[] ? K extends TColumnList[number] ? ValidateInsertSelectionKey<TTable, TSelection, K> : DrizzleTypeError<`Column "${K & string}" is not included in the insert column selection`> : ValidateInsertSelectionKey<TTable, TSelection, K> };
type NoDuplicateColumns<T extends readonly unknown[], TSeen = never> = T extends readonly [infer Head, ...infer Tail] ? [Head extends TSeen ? DrizzleTypeError<`Duplicate columns are not allowed in insert selection: "${Head & string}"`> : Head, ...NoDuplicateColumns<Tail, TSeen | Head>] : T;
declare class MsSqlInsertBuilder<TTable extends MsSqlTable, TQueryResult extends QueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TOutput extends Record<string, unknown> | undefined = undefined, TColumnList extends string[] | 'all' = 'all'> {
  static readonly [entityKind]: string;
  private config;
  protected table: TTable;
  protected session: MsSqlSession;
  protected dialect: MsSqlDialect;
  constructor(table: TTable, session: MsSqlSession, dialect: MsSqlDialect, output?: SelectedFieldsOrdered, columnList?: string[]);
  values(value: MsSqlInsertValue<TTable, TColumnList>): MsSqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT, TOutput>;
  values(values: MsSqlInsertValue<TTable, TColumnList>[]): MsSqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT, TOutput>;
  select<TSelection extends MsSqlInsertSelection<TTable, TColumnList>>(selectQuery: (qb: QueryBuilder) => TypedQueryBuilder<NoUnknownKeysInInsertSelection<TTable, TSelection, TColumnList>>): MsSqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT, TOutput>;
  select(selectQuery: (qb: QueryBuilder) => SQL): MsSqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT, TOutput>;
  select(selectQuery: SQL): MsSqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT, TOutput>;
  select<TSelection extends MsSqlInsertSelection<TTable, TColumnList>>(selectQuery: TypedQueryBuilder<NoUnknownKeysInInsertSelection<TTable, TSelection, TColumnList>>): MsSqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT, TOutput>;
  /**
   * Adds an `output` clause to the query.
   *
   * Calling this method will return the specified fields of the inserted rows. If no fields are specified, all fields will be returned.
   *
   * @example
   * ```ts
   * // Insert one row and return all fields
   * const insertedCar: Car[] = await db.insert(cars)
   *   .output();
   *   .values({ brand: 'BMW' })
   *
   * // Insert one row and return only the id
   * const insertedCarId: { id: number }[] = await db.insert(cars)
   *   .output({ id: cars.id });
   *   .values({ brand: 'BMW' })
   * ```
   */
  output(): Omit<MsSqlInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT, InferSelectModel<TTable>>, 'output'>;
  output<SelectedFields extends SelectedFieldsFlat>(fields: SelectedFields): Omit<MsSqlInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT, SelectResultFields<SelectedFields>>, 'output'>;
}
type MsSqlInsertWithout<T extends AnyMsSqlInsert, TDynamic extends boolean, K extends keyof T & string> = TDynamic extends true ? T : Omit<MsSqlInsertBase<T['_']['table'], T['_']['queryResult'], T['_']['preparedQueryHKT'], T['_']['output'], TDynamic, T['_']['excludedMethods'] | K>, T['_']['excludedMethods'] | K>;
type MsSqlInsertDynamic<T extends AnyMsSqlInsert> = MsSqlInsert<T['_']['table'], T['_']['queryResult'], T['_']['preparedQueryHKT'], T['_']['output']>;
type MsSqlInsertPrepare<T extends AnyMsSqlInsert> = PreparedQueryKind<T['_']['preparedQueryHKT'], PreparedQueryConfig & {
  execute: T['_']['output'] extends undefined ? QueryResultKind<T['_']['queryResult'], any> : T['_']['output'][];
  iterator: never;
}>;
type MsSqlInsert<TTable extends MsSqlTable = MsSqlTable, TQueryResult extends QueryResultHKT = AnyQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase, TOutput extends Record<string, unknown> | undefined = Record<string, unknown> | undefined> = MsSqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT, TOutput, true, never>;
type AnyMsSqlInsert = MsSqlInsertBase<any, any, any, any, any, any>;
interface MsSqlInsertBase<TTable extends MsSqlTable, TQueryResult extends QueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TOutput extends Record<string, unknown> | undefined = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise<TOutput extends undefined ? QueryResultKind<TQueryResult, any> : TOutput[]>, SQLWrapper {
  readonly _: {
    readonly table: TTable;
    readonly queryResult: TQueryResult;
    readonly preparedQueryHKT: TPreparedQueryHKT;
    readonly output: TOutput;
    readonly dynamic: TDynamic;
    readonly excludedMethods: TExcludedMethods;
  };
}
declare class MsSqlInsertBase<TTable extends MsSqlTable, TQueryResult extends QueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TOutput extends Record<string, unknown> | undefined = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise<TOutput extends undefined ? QueryResultKind<TQueryResult, any> : TOutput[]> implements SQLWrapper {
  private session;
  private dialect;
  static readonly [entityKind]: string;
  protected $table: TTable;
  private config;
  constructor(table: TTable, values: MsSqlInsertConfig['values'], session: MsSqlSession, dialect: MsSqlDialect, output?: SelectedFieldsOrdered, columnList?: string[], select?: boolean);
  toSQL(): Query;
  prepare(): MsSqlInsertPrepare<this>;
  execute(placeholderValues?: Record<string, unknown>): Promise<TOutput extends undefined ? QueryResultKind<TQueryResult, any> : TOutput[]>;
  private createIterator;
  iterator: ReturnType<this["prepare"]>["iterator"];
  $dynamic(): MsSqlInsertDynamic<this>;
}
//#endregion
export { AnyMsSqlInsert, MsSqlInsert, MsSqlInsertBase, MsSqlInsertBuilder, MsSqlInsertConfig, MsSqlInsertDynamic, MsSqlInsertPrepare, MsSqlInsertSelection, MsSqlInsertValue, MsSqlInsertWithout, NoDuplicateColumns, NoUnknownKeysInInsertSelection, ValidateInsertSelectionKey };
//# sourceMappingURL=insert.d.cts.map