/**
 * Order/Sort Utilities Module for Drizzle ORM
 *
 * This module provides sorting utilities that convert Sequelize-style
 * sort objects into Drizzle ORM orderBy clauses.
 *
 * Features:
 * - Convert sort objects to Drizzle orderBy
 * - Support ascending/descending sort
 * - Handle nested relation sorting
 * - Support special fields (aggregate functions, computed columns)
 * - Full-text search relevance ranking
 */
import { SQL } from 'drizzle-orm';
import { PgColumn } from 'drizzle-orm/pg-core';
import type { SortDirection, SortObject, SortContext } from '../types/index.js';
export type { SortDirection, SortObject, SortContext };
/**
 * Convert Sequelize-style sort object to Drizzle orderBy array
 *
 * @param sort - Sort object or JSON string
 * @param ctx - Sort context with table schema
 * @returns Array of Drizzle orderBy SQL expressions
 *
 * @example
 * ```typescript
 * const sort = { name: 'ASC', createdAt: 'DESC' };
 *
 * const orderBy = drizzleOrder(sort, {
 *   table: usersTable,
 *   tableName: 'users',
 *   schema: usersTable
 * });
 *
 * // Use in query:
 * const results = await db.select().from(usersTable).orderBy(...orderBy);
 * ```
 */
export declare function drizzleOrder(sort: SortObject | string | null | undefined, ctx: SortContext): SQL[];
/**
 * Apply full-text search ranking to sort
 * Used for relevance-based sorting when searching
 *
 * @param searchFields - Fields to search in
 * @param searchQuery - Search query string
 * @param ctx - Sort context
 * @returns SQL for ts_rank ordering
 */
export declare function applyFullTextSearchRanking(searchFields: string[], searchQuery: string, ctx: SortContext): SQL;
/**
 * Sort by aggregate function result
 * Example: Sort by count of related records
 */
export declare function sortByAggregate(aggregateExpression: SQL, direction?: SortDirection): SQL;
/**
 * Sort by distance (for geo queries)
 *
 * @param fieldName - The geometry/geography field name
 * @param referencePoint - GeoJSON point to measure distance from
 * @param direction - Sort direction (usually ASC for nearest first)
 */
export declare function sortByDistance(fieldName: string, referencePoint: {
    type: string;
    coordinates: [number, number];
}, direction?: SortDirection): SQL;
/**
 * Sort by vector distance (for pgvector queries)
 *
 * @param column - The Drizzle PgColumn for the vector field
 * @param queryVector - The query vector to measure distance from
 * @param operator - Distance metric: 'l2' | 'cosine' | 'innerProduct' | 'l1'
 * @param direction - Sort direction (ASC = nearest first; DESC for inner product)
 */
export declare function sortByVectorDistance(column: PgColumn, queryVector: number[], operator?: 'l2' | 'cosine' | 'innerProduct' | 'l1', direction?: SortDirection): SQL;
/**
 * Sort by CASE expression (conditional sorting)
 * Useful for custom sort orders
 *
 * @example
 * ```typescript
 * // Sort by status: active first, then pending, then inactive
 * const sortExpr = sortByCase({
 *   field: 'status',
 *   cases: [
 *     { when: 'active', then: 1 },
 *     { when: 'pending', then: 2 },
 *     { when: 'inactive', then: 3 }
 *   ],
 *   direction: 'ASC'
 * });
 * ```
 */
export declare function sortByCase(options: {
    field: string;
    cases: Array<{
        when: any;
        then: number;
    }>;
    direction?: SortDirection;
    defaultValue?: number;
}): SQL;
/**
 * Sort nulls first or last
 * PostgreSQL default: ASC puts nulls last, DESC puts nulls first
 * This function allows explicit control
 */
export declare function sortWithNulls(column: PgColumn, direction?: SortDirection, nullsFirst?: boolean): SQL;
/**
 * Parse sort string formats
 * Supports various input formats:
 * - "name" -> { name: 'ASC' }
 * - "-name" -> { name: 'DESC' }
 * - "name,createdAt" -> { name: 'ASC', createdAt: 'ASC' }
 * - "-name,createdAt" -> { name: 'DESC', createdAt: 'ASC' }
 */
export declare function parseSortString(sortStr: string): SortObject;
/**
 * Combine multiple sort criteria
 * Earlier criteria take precedence
 */
export declare function combineSorts(...sorts: (SortObject | null | undefined)[]): SortObject;
/**
 * Default sort (by ID descending for most recent first)
 */
export declare function defaultSort(ctx: SortContext): SQL[];
//# sourceMappingURL=orderUtils.d.ts.map