import { QueryBuilder } from "./query-builder.cjs";
import { SelectedFieldsFlat, SelectedFieldsOrdered } from "./select.types.cjs";
import { AnySQLiteColumn } from "../columns/common.cjs";
import { SQLiteUpdateSetSource } from "./update.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 { Subquery } from "../../subquery.cjs";
import { InferInsertModel } from "../../table.cjs";
import { Assume, DrizzleTypeError } from "../../utils.cjs";
import { SQLiteTable } from "../table.cjs";
import { SQLiteDialect } from "../dialect.cjs";
import { SQLiteSession } from "../session.cjs";
import { IndexColumn } from "../indexes.cjs";

//#region src/sqlite-core/query-builders/insert.d.ts
interface SQLiteInsertConfig<TTable extends SQLiteTable = SQLiteTable> {
  table: TTable;
  values: Record<string, unknown>[] | TypedQueryBuilder<SQLiteInsertSelection<TTable>> | SQL;
  withList?: Subquery[];
  onConflict?: SQL[];
  returning?: SelectedFieldsOrdered;
  select?: boolean;
  columnList?: string[];
}
type SQLiteInsertValue<TTable extends SQLiteTable, 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 SQLiteInsertSelection<TTable extends SQLiteTable, 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]>]: AnySQLiteColumn | SQL | SQL.Aliased | TModel[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;
type ValidateInsertSelectionKey<TTable extends SQLiteTable, TSelection extends SQLiteInsertSelection<any>, K extends keyof TSelection> = K extends keyof InferInsertModel<TTable> ? TSelection[K] : K extends keyof InferInsertModel<TTable, {
  override: true;
}> ? DrizzleTypeError<`Column "${K & string}" in table "${TTable['_']['name']}" is a generated column - manual value insertion restricted`> : DrizzleTypeError<`Column "${K & string}" does not exist in table "${TTable['_']['name']}"`>;
type NoUnknownKeysInInsertSelection<TTable extends SQLiteTable, TSelection extends SQLiteInsertSelection<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> };
interface SQLiteInsertBuilderConstructor {
  new (table: SQLiteTable, values: SQLiteInsertConfig['values'], session: SQLiteSession<any, any>, dialect: SQLiteDialect, withList?: Subquery[], select?: boolean, columnList?: string[]): AnySQLiteInsert;
}
declare class SQLiteInsertBuilder<TTable extends SQLiteTable, TRunResult, TColumnList extends string[] | 'all' = 'all', THKT extends SQLiteInsertHKTBase = SQLiteInsertQueryBuilderHKT> {
  protected table: TTable;
  protected session: SQLiteSession<any, any>;
  protected dialect: SQLiteDialect;
  private withList?;
  private columnList?;
  private builder;
  static readonly [entityKind]: string;
  constructor(table: TTable, session: SQLiteSession<any, any>, dialect: SQLiteDialect, withList?: Subquery[] | undefined, columnList?: string[] | undefined, builder?: SQLiteInsertBuilderConstructor);
  values(value: SQLiteInsertValue<TTable, TColumnList>): SQLiteInsertKind<THKT, TTable, TRunResult>;
  values(values: SQLiteInsertValue<TTable, TColumnList>[]): SQLiteInsertKind<THKT, TTable, TRunResult>;
  select<TSelection extends SQLiteInsertSelection<TTable, TColumnList>>(selectQuery: (qb: QueryBuilder) => TypedQueryBuilder<NoUnknownKeysInInsertSelection<TTable, TSelection, TColumnList>>): SQLiteInsertKind<THKT, TTable, TRunResult>;
  select(selectQuery: (qb: QueryBuilder) => SQL): SQLiteInsertKind<THKT, TTable, TRunResult>;
  select(selectQuery: SQL): SQLiteInsertKind<THKT, TTable, TRunResult>;
  select<TSelection extends SQLiteInsertSelection<TTable, TColumnList>>(selectQuery: TypedQueryBuilder<NoUnknownKeysInInsertSelection<TTable, TSelection, TColumnList>>): SQLiteInsertKind<THKT, TTable, TRunResult>;
}
interface SQLiteInsertHKTBase {
  table: unknown;
  resultType: unknown;
  runResult: unknown;
  returning: unknown;
  dynamic: boolean;
  excludedMethods: string;
  result: unknown;
  _type: unknown;
}
interface SQLiteInsertQueryBuilderHKT extends SQLiteInsertHKTBase {
  _type: SQLiteInsertBase<SQLiteInsertQueryBuilderHKT, Assume<this['table'], SQLiteTable>, this['runResult'], this['returning'], this['dynamic'], this['excludedMethods']>;
}
type SQLiteInsertKind<T extends SQLiteInsertHKTBase, TTable extends SQLiteTable, TRunResult, TReturning = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> = (T & {
  table: TTable;
  runResult: TRunResult;
  returning: TReturning;
  dynamic: TDynamic;
  excludedMethods: TExcludedMethods;
})['_type'];
type SQLiteInsertWithout<T extends AnySQLiteInsert, TDynamic extends boolean, K extends keyof T & string> = TDynamic extends true ? T : Omit<SQLiteInsertKind<T['_']['hkt'], T['_']['table'], T['_']['runResult'], T['_']['returning'], TDynamic, T['_']['excludedMethods'] | K>, T['_']['excludedMethods'] | K>;
type SQLiteInsertReturning<T extends AnySQLiteInsert, TDynamic extends boolean, TSelectedFields extends SelectedFieldsFlat> = SQLiteInsertWithout<SQLiteInsertKind<T['_']['hkt'], T['_']['table'], T['_']['runResult'], SelectResultFields<TSelectedFields>, TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>;
type SQLiteInsertReturningAll<T extends AnySQLiteInsert, TDynamic extends boolean> = SQLiteInsertWithout<SQLiteInsertKind<T['_']['hkt'], T['_']['table'], T['_']['runResult'], T['_']['table']['$inferSelect'], TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>;
type SQLiteInsertOnConflictDoUpdateConfig<T extends AnySQLiteInsert> = {
  target: IndexColumn | IndexColumn[]; /** @deprecated - use either `targetWhere` or `setWhere` */
  where?: SQL;
  targetWhere?: SQL;
  setWhere?: SQL;
  set: SQLiteUpdateSetSource<T['_']['table']>;
};
type SQLiteInsertDynamic<T extends AnySQLiteInsert> = SQLiteInsertKind<T['_']['hkt'], T['_']['table'], T['_']['runResult'], T['_']['returning'], true, never>;
type AnySQLiteInsert = SQLiteInsertBase<any, any, any, any, any, any>;
type SQLiteInsert<TTable extends SQLiteTable = SQLiteTable, TRunResult = unknown, TReturning = any> = SQLiteInsertBase<SQLiteInsertQueryBuilderHKT, TTable, TRunResult, TReturning, true, never>;
interface SQLiteInsertBase<THKT extends SQLiteInsertHKTBase, TTable extends SQLiteTable, TRunResult, TReturning = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends SQLWrapper {
  readonly _: {
    readonly dialect: 'sqlite';
    readonly hkt: THKT;
    readonly table: TTable;
    readonly runResult: TRunResult;
    readonly returning: TReturning;
    readonly dynamic: TDynamic;
    readonly excludedMethods: TExcludedMethods;
    readonly result: TReturning extends undefined ? TRunResult : TReturning[];
  };
}
declare class SQLiteInsertBase<THKT extends SQLiteInsertHKTBase, TTable extends SQLiteTable, TRunResult, TReturning = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> implements SQLWrapper {
  protected session: SQLiteSession<any, any>;
  protected dialect: SQLiteDialect;
  static readonly [entityKind]: string;
  constructor(table: TTable, values: SQLiteInsertConfig['values'], session: SQLiteSession<any, any>, dialect: SQLiteDialect, withList?: Subquery[], select?: boolean, columnList?: string[]);
  /**
   * Adds a `returning` 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.
   *
   * See docs: {@link https://orm.drizzle.team/docs/insert#insert-returning}
   *
   * @example
   * ```ts
   * // Insert one row and return all fields
   * const insertedCar: Car[] = await db.insert(cars)
   *   .values({ brand: 'BMW' })
   *   .returning();
   *
   * // Insert one row and return only the id
   * const insertedCarId: { id: number }[] = await db.insert(cars)
   *   .values({ brand: 'BMW' })
   *   .returning({ id: cars.id });
   * ```
   */
  returning(): SQLiteInsertReturningAll<this, TDynamic>;
  returning<TSelectedFields extends SelectedFieldsFlat>(fields: TSelectedFields): SQLiteInsertReturning<this, TDynamic, TSelectedFields>;
  /**
   * Adds an `on conflict do nothing` clause to the query.
   *
   * Calling this method simply avoids inserting a row as its alternative action.
   *
   * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
   *
   * @param config The `target` and `where` clauses.
   *
   * @example
   * ```ts
   * // Insert one row and cancel the insert if there's a conflict
   * await db.insert(cars)
   *   .values({ id: 1, brand: 'BMW' })
   *   .onConflictDoNothing();
   *
   * // Explicitly specify conflict target
   * await db.insert(cars)
   *   .values({ id: 1, brand: 'BMW' })
   *   .onConflictDoNothing({ target: cars.id });
   * ```
   */
  onConflictDoNothing(config?: {
    target?: IndexColumn | IndexColumn[];
    where?: SQL;
  }): this;
  /**
   * Adds an `on conflict do update` clause to the query.
   *
   * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
   *
   * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
   *
   * @param config The `target`, `set` and `where` clauses.
   *
   * @example
   * ```ts
   * // Update the row if there's a conflict
   * await db.insert(cars)
   *   .values({ id: 1, brand: 'BMW' })
   *   .onConflictDoUpdate({
   *     target: cars.id,
   *     set: { brand: 'Porsche' }
   *   });
   *
   * // Upsert with 'where' clause
   * await db.insert(cars)
   *   .values({ id: 1, brand: 'BMW' })
   *   .onConflictDoUpdate({
   *     target: cars.id,
   *     set: { brand: 'newBMW' },
   *     where: sql`${cars.createdAt} > '2023-01-01'::date`,
   *   });
   * ```
   */
  onConflictDoUpdate(config: SQLiteInsertOnConflictDoUpdateConfig<this>): this;
  getSQL(): SQL;
  toSQL(): Query;
  $dynamic(): SQLiteInsertDynamic<this>;
}
//#endregion
export { AnySQLiteInsert, NoDuplicateColumns, NoUnknownKeysInInsertSelection, SQLiteInsert, SQLiteInsertBase, SQLiteInsertBuilder, SQLiteInsertBuilderConstructor, SQLiteInsertConfig, SQLiteInsertDynamic, SQLiteInsertHKTBase, SQLiteInsertKind, SQLiteInsertOnConflictDoUpdateConfig, SQLiteInsertQueryBuilderHKT, SQLiteInsertReturning, SQLiteInsertReturningAll, SQLiteInsertSelection, SQLiteInsertValue, SQLiteInsertWithout, ValidateInsertSelectionKey };
//# sourceMappingURL=insert.d.cts.map