/**
 * Aggregation Utilities Module for Drizzle ORM
 *
 * This module provides aggregation functions (count, sum, avg, min, max)
 * for Drizzle ORM, matching Sequelize aggregation capabilities.
 *
 * Features:
 * - Standard aggregations (COUNT, SUM, AVG, MIN, MAX)
 * - DISTINCT count
 * - ARRAY_AGG for array aggregation
 * - Date part extraction (YEAR, MONTH, DAY, etc.)
 * - GROUP BY support
 * - Aggregate with relations
 */
import { SQL } from 'drizzle-orm';
import { PgColumn } from 'drizzle-orm/pg-core';
import type { AggregateFunction, AggregateConfig, AggregateMapping, AggregateContext, DatePart, DateTruncPrecision } from '../types/index.js';
export type { AggregateFunction, AggregateConfig, AggregateMapping, AggregateContext, DatePart, DateTruncPrecision };
/**
 * Create aggregate function SQL
 * Uses built-in aggregate functions and sql<type> template tags
 */
export declare function createAggregateFunction(func: AggregateFunction, column: PgColumn | SQL, ctx?: AggregateContext): SQL;
/**
 * Process date extraction for GROUP BY
 * Format: "date:year:column" -> EXTRACT(YEAR FROM column)
 */
export declare function processDateExtraction(field: string, column?: PgColumn | SQL): {
    expression: SQL;
    alias: string;
} | null;
/**
 * Build aggregate attributes for SELECT clause
 *
 * @param aggregate - Aggregate mapping (alias -> config)
 * @param groupBy - Array of fields to group by
 * @param ctx - Aggregate context
 * @returns Array of [SQL expression, alias] tuples
 *
 * @example
 * ```typescript
 * const aggregate = {
 *   totalUsers: { function: 'count', field: 'id' },
 *   avgAge: { function: 'avg', field: 'age' }
 * };
 *
 * const groupBy = ['status', 'date:year:createdAt'];
 *
 * const attributes = buildAggregateAttributes(aggregate, groupBy, {
 *   tableName: 'users'
 * });
 *
 * // Use in query:
 * const results = await db
 *   .select({
 *     ...Object.fromEntries(attributes.map(([expr, alias]) => [alias, expr]))
 *   })
 *   .from(usersTable)
 *   .groupBy(...groupByExprs);
 * ```
 */
export declare function buildAggregateAttributes(aggregate: AggregateMapping, groupBy: string[], ctx: AggregateContext): Array<[SQL, string]>;
/**
 * Build GROUP BY expressions using
 *
 * @param groupBy - Array of fields to group by
 * @param columns - Optional map of column objects to use instead of strings
 * @param pathToAliasMap - Optional map of relation paths to JOIN aliases
 * @returns Array of SQL expressions for GROUP BY clause
 */
export declare function buildGroupByExpressions(groupBy: string[], columns?: Record<string, PgColumn | SQL>, pathToAliasMap?: Map<string, string>, tableName?: string): SQL[];
/**
 * Count records with optional distinct
 *
 * @param column - Column to count (or '*' for all)
 * @param distinct - Whether to count distinct values only
 */
export declare function countRecords(column?: PgColumn | SQL, distinct?: boolean): SQL;
/**
 * Sum column values
 */
export declare function sumColumn(column: PgColumn | SQL): SQL;
/**
 * Average column values
 */
export declare function avgColumn(column: PgColumn | SQL): SQL;
/**
 * Minimum column value
 */
export declare function minColumn(column: PgColumn | SQL): SQL;
/**
 * Maximum column value
 */
export declare function maxColumn(column: PgColumn | SQL): SQL;
/**
 * Array aggregation (collect values into array)
 */
export declare function arrayAgg(column: PgColumn | SQL, distinct?: boolean): SQL;
/**
 * String aggregation (concatenate values)
 */
export declare function stringAgg(column: PgColumn | SQL, delimiter?: string): SQL;
/**
 * JSON aggregation (collect rows as JSON array)
 */
export declare function jsonAgg(rowExpression: SQL): SQL;
/**
 * Date part extraction using
 *
 * @param part - Date part to extract (year, month, day, hour, minute, week, dow, isodow)
 * @param column - Date/timestamp column
 * @example
 * const yearCol = extractDatePart('year', users.createdAt);
 * // Equivalent to: EXTRACT(YEAR FROM users.createdAt)
 */
export declare function extractDatePart(part: DatePart, column: PgColumn | SQL): SQL<number>;
/**
 * Date truncation
 *
 * @param precision - Time precision (day, week, month, year, hour, minute)
 * @param column - Date/timestamp column
 * @example
 * const dailyGroups = truncateDate('day', orders.createdAt);
 * // Equivalent to: DATE_TRUNC('day', orders.createdAt)
 */
export declare function truncateDate(precision: DateTruncPrecision, column: PgColumn | SQL): SQL<Date>;
/**
 * Conditional count (COUNT with CASE WHEN)
 *
 * @example
 * ```typescript
 * // Count active users
 * const activeCount = conditionalCount(
 *   eq(usersTable.status, 'active')
 * );
 * ```
 */
export declare function conditionalCount(condition: SQL): SQL;
/**
 * Conditional sum (SUM with CASE WHEN)
 */
export declare function conditionalSum(column: PgColumn | SQL, condition: SQL): SQL;
/**
 * Percentile calculation
 *
 * @param column - Numeric column
 * @param percentile - Percentile value (0.0 to 1.0)
 * @param discrete - Use discrete (percentile_disc) vs continuous (percentile_cont)
 * @example
 * const median = calculatePercentile(sales.amount, 0.5);
 * // Equivalent to: PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY sales.amount)
 */
export declare function calculatePercentile(column: PgColumn | SQL, percentile: number, discrete?: boolean): SQL<number>;
/**
 * Standard deviation
 */
export declare function stddev(column: PgColumn | SQL, population?: boolean): SQL<number>;
/**
 * Variance
 */
export declare function variance(column: PgColumn | SQL, population?: boolean): SQL<number>;
/**
 * Coalesce (return first non-null value)
 */
export declare function coalesce(...values: Array<PgColumn | SQL | any>): SQL;
/**
 * Full-text search matching
 * @param columns - Array of column objects to search
 * @param searchQuery - Search query string
 * @returns SQL condition for full-text matching
 */
export declare function applyFullTextSearch(columns: Array<PgColumn | SQL>, searchQuery: string): SQL<boolean>;
/**
 * Geographic distance calculation
 *
 * @param column - Geography/geometry column
 * @param targetPoint - GeoJSON point
 * @returns SQL for distance in meters
 */
export declare function calculateDistance(column: PgColumn | SQL, targetPoint: {
    type: string;
    coordinates: [number, number];
}): SQL<number>;
/**
 * Build HAVING clause from filter
 * Similar to WHERE but for aggregate results
 *
 * Note: HAVING clause is not currently used in the application.
 * This is a placeholder for future implementation if aggregate filtering is needed.
 */
export declare function buildHavingClause(filter: Record<string, any>): SQL | undefined;
//# sourceMappingURL=aggregationUtils.d.ts.map