import { Column, IRowNode } from 'ag-grid-enterprise';
import { BaseContext, CellDataChangedInfo } from '../../../types';
/**
 * An AST Expression
 */
export type AST = AST_Expression[];
export type PredicateType = 'VALUE_REF' | 'INFIX' | 'UNARY' | 'FUNCTION' | 'CONDITIONAL';
/**
 * Defines AST of an Expressoin
 */
export type AST_Expression = AST_Function | boolean | number | string;
/**
 * Defines AST of an Expression Function
 */
export type AST_Function = {
    type: string;
    args: AST_Expression[];
    range?: [number, number];
    metaInfo?: PredicateType;
};
/**
 * Token used by the AdapTableQL parser
 */
export type Token = {
    type: string;
    value: string;
    range: [number, number];
};
/**
 * Provides context to an Expression Function, including current row node and AdaptableApi
 */
export interface ExpressionContext extends BaseContext {
    /**
     * Current AG Grid Row Node being evaluated
     */
    node: IRowNode;
    /**
     * All Expression Functions available to AdaptableQL
     */
    functions: ExpressionFunctionMap<string>;
    /**
     * Expression Functions available to AdaptableQL in (optional) WHERE clause
     */
    whereClauseFunctions?: ExpressionFunctionMap<string>;
    /**
     * Optional filter function to be applied before evaluating the expression
     */
    filterFn?: (any: any) => boolean;
    /**
     * All Named Query evaluations: tracked in order to detect circular dependencies
     */
    namedQueryCallStack?: string[];
    /**
     * Evaluate custom variables
     */
    evaluateCustomQueryVariable?: (functionName: string, args?: any[]) => any;
    /**
     * Get custom list rows
     */
    getRowNodes?: () => IRowNode[];
    /**
     * Changed cell data
     */
    dataChangedEvent?: CellDataChangedInfo;
    /**
     * Pivot Result Column when evaluating a Pivoted Column
     */
    pivotResultColumn?: Column;
}
/**
 * Key-Value map of Expression Names and their implementation
 */
export type ExpressionFunctionMap<T extends string> = Record<T | string, ExpressionFunction>;
/**
 * Defines an AdaptableQL Function used in an Adaptable Expression
 */
export interface ExpressionFunction {
    /**
     * Actual AdaptableQL Function called by the Expression (mandatory prop)
     */
    handler: ExpressionFunctionHandler;
    /**
     * Removes entry from Expression Editor's Functions dropdown
     */
    isHiddenFromMenu?: boolean;
    /**
     * What the AdaptableQL Function does
     */
    description?: string;
    /**
     * How the AdaptableQL Function should be called
     */
    signatures?: string[];
    /**
     * Type returned by Function: boolean, number, string, date, any
     */
    returnType?: 'boolean' | 'number' | 'string' | 'date' | 'null' | 'any';
    /**
     * Used to group Functions Expression Editor dropdown
     */
    category?: ExpressionCategory;
    /**
     * Examples that demonstrate the AdaptableQL Function
     */
    examples?: string[];
    /**
     * Whether Expression is evaluated without handling inner AST nodes
     */
    hasEagerEvaluation?: boolean;
    /**
     * Data Types of Inputs required by Expression
     */
    inputs?: ExpressionFunctionInputType[] | ExpressionFunctionInputType[][];
}
/**
 * Data Types of Inputs used by Expression (test, number, date, boolean)
 */
export type ExpressionFunctionInputType = 'text' | 'number' | 'date' | 'boolean' | 'number[]' | 'date[]' | 'text[]';
/**
 * Categories for Expression Functions
 */
export type ExpressionCategory = 'logical' | 'comparison' | 'strings' | 'maths' | 'dates' | 'conditional' | 'special' | string;
/**
 * Defines how an AdaptableQL Function is described in Expression Editor
 */
export type ExpressionFunctionDocBlock = {
    type: 'code';
    content: string;
} | {
    type: 'paragraph';
    content: string;
};
/**
 * The javascript function which is invoked by an AdaptableQL Function
 */
export type ExpressionFunctionHandler = (
/**
 * Args passed into function to enable evaluation
 */
args: any[], 
/**
 * Context Object - including current RowNode and AdaptableAPI
 */
context: ExpressionContext) => any;
export declare const isAST_Function: (node: AST_Expression) => node is AST_Function;
/**
 * Defines an AdapTableQL function that aggregates data
 */
export interface AggregatedExpressionFunction {
    /**
     * Description of the Aggregated Expression Function
     */
    description?: string;
    /**
     * Example Signatures for the Aggregated Expression Function
     */
    signatures?: string[];
    /**
     * Examples to use the Aggregated Expression Function
     */
    examples?: string[];
    /**
     * Mandatory Initial Value for the aggregation
     */
    initialValue: any;
    /**
     * Mandatory Reducer function which is called for each value(row) in the Column Data
     */
    reducer: (context: AggregatedExpressionReducerContext) => any;
    /**
     * Called AFTER the reducer() has processed all values / rows
     * Can be used to change result of reducer based on the values array (e.g. average = aggregated value / count)
     */
    processAggregatedValue?: (context: AggregatedExpressionProcessAggValueContext) => any;
    /**
     * Called for each row AFTER the reducer() and processAggregatedValue() functions
     * Can be used when each row has a different aggregated value (e.g. percentage = row value / aggregated value).
     * Returns return value for each individual row
     */
    prepareRowValue?: (context: AggregatedExpressionPrepareRowValueContext) => number | string | Date | undefined;
    /**
     * Optional filter which is applied to each row before the reducer is called. If the filter returns false, the row is NOT included in the aggregation.
     */
    filterRow?: (context: AggregatedExpressionFilterRowContext) => boolean;
    /**
     * Optional argument types.
     */
    inputTypes?: ExpressionFunctionInputType[];
}
/**
 * Context used by the reducer property in Aggregated Expressions
 */
export interface AggregatedExpressionReducerContext extends BaseContext {
    /**
     * Value returned by the previous call to the reducer function, or the initialValue if this is the first call. You return the new accumulator value from this function.
     */
    accumulator: any;
    /**
     * Current value being processed in the Column Data
     */
    currentValue: any;
    /**
     * Index of the current value in the Column Data
     */
    index: number;
    /**
     * Current row node
     */
    rowNode: IRowNode;
    /**
     * Arguments passed to the function
     */
    args: any[];
    /**
     * Column Id of the column being aggregated
     */
    aggColumnId: string;
    /**
     * Column Id(s) of the column(s) being grouped by
     */
    groupByColumnIds?: string[];
    /**
     * Helper function to get the value of a column
     * @param colId column id
     */
    getValueForColId: (colId: string) => any;
}
/**
 * Context used by processAggregatedValue property in Aggregated Expressions
 */
export interface AggregatedExpressionProcessAggValueContext extends BaseContext {
    /**
     * Result of the reducer
     */
    aggregatedValue: any;
    /**
     * Array of row nodes; if aggregation is grouped, this will be the array of row nodes for the group
     */
    rowNodes: IRowNode[];
    /**
     * Arguments passed to the function
     */
    args: any[];
    /**
     * Column Id of the column being aggregated
     */
    aggColumnId: string;
    /**
     * Column Id(s) of the column(s) being grouped by
     */
    groupByColumnIds?: string[];
}
/**
 * Context used by prepareRowValue property in Aggregated Expressions
 */
export interface AggregatedExpressionPrepareRowValueContext extends BaseContext {
    /**
     * Current Row Node
     */
    rowNode: IRowNode;
    /**
     * Result of the reducer
     */
    aggregatedValue: any;
    /**
     * Arguments passed to the function
     */
    args: any[];
    /**
     * Column Id of the column being aggregated
     */
    aggColumnId: string;
    /**
     * Column Id(s) of the column(s) being grouped by
     */
    groupByColumnIds?: string[];
    /**
     * Helper function to get the value of a column
     * @param colId column id
     */
    getValueForColId: (colId: string) => any;
}
/**
 * Context used when applying a filter to Rows before Reducer is called
 */
export interface AggregatedExpressionFilterRowContext extends BaseContext {
    /**
     * Current row node
     */
    rowNode: IRowNode;
    /**
     * Arguments passed to the function
     */
    args: any[];
    /**
     * Column Id of the column being aggregated
     * Usually the first Col argument, e.g. [colId]
     */
    aggColumnId: string;
    /**
     * Column Id(s) of the column(s) being grouped by
     */
    groupByColumnIds?: string[];
    /**
     * Utility function to get the value of a column
     * @param colId column id
     */
    getValueForColId: (colId: string) => any;
}
