import { type Dictionary, LockMode, type QueryFlag, RawQueryFragment, type Subquery } from '@mikro-orm/core';
import { QueryType } from './enums.js';
import type { AbstractSqlPlatform } from '../AbstractSqlPlatform.js';
/** Options for Common Table Expression (CTE) definitions. */
export interface CteOptions {
  /** Column names for the CTE. */
  columns?: string[];
  /** PostgreSQL: MATERIALIZED / NOT MATERIALIZED */
  materialized?: boolean;
}
interface CteClause extends CteOptions {
  name: string;
  sql: string;
  params: unknown[];
  recursive?: boolean;
}
interface Options {
  tableName?: string | RawQueryFragment;
  indexHint?: string;
  select?: (string | RawQueryFragment)[];
  distinct?: boolean;
  distinctOn?: string[];
  joins?: {
    sql: string;
    params: unknown[];
  }[];
  groupBy?: (string | RawQueryFragment)[];
  where?: {
    sql: string;
    params: unknown[];
  };
  having?: {
    sql: string;
    params: unknown[];
  };
  orderBy?: string;
  limit?: number;
  offset?: number;
  data?: Dictionary;
  onConflict?: OnConflictClause;
  lockMode?: LockMode;
  lockTables?: string[];
  returning?: (string | RawQueryFragment | [name: string, type: unknown])[];
  comment?: string[];
  hintComment?: string[];
  flags?: Set<QueryFlag>;
  wrap?: [prefix: string, suffix: string];
  ctes?: CteClause[];
}
/** Options for specifying the target table in FROM/INTO clauses. */
export interface TableOptions {
  schema?: string;
  indexHint?: string;
  alias?: string;
}
interface OnConflictClause {
  fields: string[] | RawQueryFragment;
  ignore?: boolean;
  merge?: Dictionary | (string | RawQueryFragment)[];
  where?: {
    sql: string;
    params: unknown[];
  };
}
/** @internal */
export declare class NativeQueryBuilder implements Subquery {
  protected readonly platform: AbstractSqlPlatform;
  readonly __subquery: true;
  protected type?: QueryType;
  protected parts: string[];
  protected params: unknown[];
  protected options: Options;
  constructor(platform: AbstractSqlPlatform);
  select(fields: string | RawQueryFragment | (string | RawQueryFragment)[]): this;
  count(fields?: string | RawQueryFragment | (string | RawQueryFragment)[], distinct?: boolean): this;
  into(tableName: string | RawQueryFragment | NativeQueryBuilder, options?: TableOptions): this;
  from(tableName: string | RawQueryFragment | NativeQueryBuilder, options?: TableOptions): this;
  where(sql: string, params: unknown[]): this;
  having(sql: string, params: unknown[]): this;
  groupBy(groupBy: (string | RawQueryFragment)[]): this;
  join(sql: string, params: unknown[]): this;
  orderBy(orderBy: string): this;
  /**
   * The sub-query is compiled eagerly at call time — later mutations to the
   * sub-query builder will not be reflected in this CTE.
   */
  with(name: string, query: NativeQueryBuilder | RawQueryFragment, options?: CteOptions): this;
  /**
   * Adds a recursive CTE (`WITH RECURSIVE` on PostgreSQL/MySQL/SQLite, plain `WITH` on MSSQL).
   * The sub-query is compiled eagerly — later mutations will not be reflected.
   */
  withRecursive(name: string, query: NativeQueryBuilder | RawQueryFragment, options?: CteOptions): this;
  private addCte;
  toString(): string;
  compile(): {
    sql: string;
    params: unknown[];
  };
  protected addLockClause(): void;
  protected addOnConflictClause(): void;
  protected combineParts(): {
    sql: string;
    params: unknown[];
  };
  limit(limit: number): this;
  offset(offset: number): this;
  insert(data: Dictionary): this;
  update(data: Dictionary): this;
  delete(): this;
  truncate(): this;
  distinct(): this;
  distinctOn(fields: string[]): this;
  onConflict(options: OnConflictClause): OnConflictClause;
  returning(fields: (string | RawQueryFragment | [name: string, type: unknown])[]): this;
  lockMode(lockMode: LockMode, lockTables?: string[]): this;
  comment(comment: string | string[]): this;
  hintComment(comment: string | string[]): this;
  setFlags(flags: Set<QueryFlag>): this;
  clear(clause: keyof Options): this;
  wrap(prefix: string, suffix: string): this;
  as(alias: string): this;
  toRaw(): RawQueryFragment;
  protected compileSelect(): void;
  protected getFields(): string;
  protected compileInsert(): void;
  protected addOutputClause(type: 'inserted' | 'deleted'): void;
  protected processInsertData(): string[];
  protected compileUpdate(): void;
  protected compileDelete(): void;
  protected compileTruncate(): void;
  protected addHintComment(): void;
  protected compileCtes(): void;
  protected getCteKeyword(hasRecursive: boolean): string;
  protected getTableName(): string;
  protected quote(id: string | RawQueryFragment | NativeQueryBuilder): string;
}
export {};
