import type { AggregateNode, AggregateRecord, MetricsRecord } from './@types/aggregate.js';
import type { AnyDB } from './@types/internal-types.js';
import type { AggregationHelper } from './aggregation-helpers.js';
import { Executor } from './executor.js';
import { FilterableQueryBuilder } from './where-query-builder.js';
/**
 * A query builder for performing aggregation queries.
 * @template DB - The database type.
 * @template TableName - The name of the table to aggregate from.
 * @template TGroupBy - The fields to group by.
 * @template TAggregations - The aggregations to perform.
 */
export declare class AggregationQueryBuilder<DB extends AnyDB, TableName extends keyof DB, TGroupBy extends readonly (keyof DB[TableName] & string)[] = [], TAggregations extends {
    [K in keyof DB[TableName] & string]?: readonly (keyof DB[TableName][K]['aggregations'])[];
} = object, TMetrics extends Record<string, AggregationHelper> | undefined = undefined> extends FilterableQueryBuilder<DB, TableName> {
    #private;
    constructor(node: AggregateNode, executor: Executor, metrics?: TMetrics);
    /**
     * Groups the results by a specified field.
     * @param field - The field to group by.
     * @param direction - The sort direction for the grouping.
     * @returns A new `AggregationQueryBuilder` instance with the grouping applied.
     *
     * @example
     * ```typescript
     * const userCounts = await qb
     *   .aggregateFrom('users')
     *   .groupBy('role')
     *   .metrics({ count: count('id') })
     *   .execute();
     * ```
     */
    groupBy<const TField extends keyof DB[TableName] & string>(field: TField, direction?: 'asc' | 'desc'): AggregationQueryBuilder<DB, TableName, [
        ...TGroupBy,
        TField
    ], TAggregations, TMetrics>;
    /**
     * Specifies the metrics to compute using helper functions.
     * Returns a flat array of records with groupBy fields and metrics at the top level.
     * @param metrics - An object where keys are metric names and values are aggregation helper functions.
     * @returns A new `AggregationQueryBuilder` instance with the metrics applied.
     *
     * @example
     * ```typescript
     * const userStats = await qb
     *   .aggregateFrom('users')
     *   .groupBy('role', 'asc')
     *   .groupBy('permission', 'desc')
     *   .metrics({
     *     idCount: count('id'),
     *     ageAvg: avg('age'),
     *     ageSum: sum('age')
     *   })
     *   .execute();
     * ```
     */
    metrics<const T extends Record<string, AggregationHelper>>(metrics: T): AggregationQueryBuilder<DB, TableName, TGroupBy, TAggregations, T>;
    /**
     * Sets the maximum number of records to return.
     * @param count - The maximum number of records.
     * @returns A new `AggregationQueryBuilder` instance with the limit applied.
     */
    limit(count: number): AggregationQueryBuilder<DB, TableName, TGroupBy, TAggregations, TMetrics>;
    /**
     * Sets the number of records to skip.
     * @param count - The number of records to skip.
     * @returns A new `AggregationQueryBuilder` instance with the offset applied.
     */
    offset(count: number): AggregationQueryBuilder<DB, TableName, TGroupBy, TAggregations, TMetrics>;
    /**
     * Paginates the results.
     * @param page - The page number to retrieve.
     * @param limit - The number of records per page.
     * @returns A new `AggregationQueryBuilder` instance with pagination applied.
     */
    paginate(page: number, limit: number): AggregationQueryBuilder<DB, TableName, TGroupBy, TAggregations, TMetrics>;
    /**
     * Sorts the results by a specified field.
     * @param field - The field to sort by.
     * @param direction - The sort direction ('asc' or 'desc').
     * @returns A new `AggregationQueryBuilder` instance with the sorting applied.
     */
    orderBy(field: keyof DB[TableName], direction?: 'asc' | 'desc'): AggregationQueryBuilder<DB, TableName, TGroupBy, TAggregations, TMetrics>;
    /**
     * Executes the aggregation query.
     * @returns A promise that resolves with an array of the aggregation results.
     * If metrics were specified, returns a flat array. Otherwise, returns the nested structure.
     *
     * @example
     * ```typescript
     * const userCounts = await qb
     *   .aggregateFrom('users')
     *   .groupBy('role')
     *   .metrics({ count: count('id') })
     *   .execute();
     * ```
     */
    execute(): Promise<TMetrics extends Record<string, AggregationHelper> ? MetricsRecord<DB, TableName, TGroupBy, TMetrics>[] : AggregateRecord<DB, TableName, TGroupBy, TAggregations>[]>;
    /**
     * Flattens the nested AggregateRecord structure into a flat array of metrics records.
     */
    private _flattenMetrics;
    /**
     * Subscribes to the results of the aggregation query.
     * @param callback - A callback function that will be called with the results of the aggregation query.
     * @returns A function to unsubscribe from the query.
     *
     * @example
     * ```typescript
     * const unsubscribe = qb
     *   .aggregateFrom('users')
     *   .groupBy('role')
     *   .metrics({ count: count('id') })
     *   .subscribe((userCounts) => {
     *     console.log('User counts by role:', userCounts);
     *   });
     *
     * // To stop listening for updates
     * unsubscribe();
     * ```
     */
    subscribe(callback: (result: TMetrics extends Record<string, AggregationHelper> ? MetricsRecord<DB, TableName, TGroupBy, TMetrics>[] : AggregateRecord<DB, TableName, TGroupBy, TAggregations>[]) => void): Promise<{
        unsubscribe: () => Promise<void>;
    }>;
    compile(): {
        query: string;
        variables: Record<string, any>;
    };
    _prepareMetadata(): any;
}
