import { type Arg, type ArgValue, Attribute, Filter, FilterRelations, type FunctionCall, JaqlDataSourceForDto, JSONArray, Measure, PivotGrandTotals } from '@sisense/sdk-data';
import type { CommonFiltersOptions } from '../../../domains/dashboarding/common-filters/types.js';
import type { DashboardConfig, DashboardLayoutOptions, DashboardStyleOptions } from '../../../domains/dashboarding/types.js';
import { CategoryStyle, SeriesStyle, ValueStyle } from '../../../domains/visualizations/core/chart-data-options/types.js';
import type { WidgetConfig, WidgetType } from '../../../domains/widgets/components/widget/types.js';
import type { CustomWidgetStyleOptions, PivotTableStyleOptions, TextWidgetStyleOptions } from '../../../types.js';
import { DataSchemaContext, NlqTranslationInput } from '../types.js';
import type { SchemaIndex } from './shared/utils/schema-index.js';
/**
 * Internal context type that uses schemaIndex for efficient lookups
 * @internal
 */
export interface InternalDataSchemaContext {
    /** The data source being used for the query */
    dataSource: JaqlDataSourceForDto;
    /** Schema index for efficient table/column lookups */
    schemaIndex: SchemaIndex;
    /** Chart type for axis-specific translation (e.g., pivot columns, boxplot value) */
    chartType?: string;
}
export declare const DIMENSIONAL_NAME_PREFIX = "DM.";
/** Re-exported from `@sisense/sdk-data` (compose-code parse tree). */
export type { Arg, ArgValue, FunctionCall };
export type ArgType = 'string' | 'string[]' | 'number' | 'number[]' | 'boolean' | 'Attribute' | 'Attribute[]' | 'Measure' | 'BaseMeasure' | 'Measure[]' | 'Filter' | 'Filter[]' | 'FilterRelationsNode' | 'DateDimension' | 'LevelAttribute' | 'Measure | number' | 'Date | string' | 'string | number' | 'BaseFilterConfig' | 'MembersFilterConfig' | 'CustomFormulaContext' | 'any';
export interface ArgSchema {
    type: ArgType;
    required: boolean;
}
export type ProcessedArg = unknown;
export type QueryElement = Filter | FilterRelations | Measure;
export type FactoryFunction = (...args: unknown[]) => QueryElement;
/**
 * Context object passed to all custom processors containing runtime information
 * needed for processing.
 * @internal
 */
export interface FunctionContext extends InternalDataSchemaContext {
    /** Path prefix for error messages (e.g., 'args[0].function') */
    pathPrefix: string;
}
export interface ArgContext extends FunctionContext {
    argSchema: ArgSchema;
}
export type DimensionsInput = NlqTranslationInput<JSONArray, InternalDataSchemaContext>;
export type MeasuresInput = NlqTranslationInput<JSONArray, InternalDataSchemaContext>;
export type FiltersInput = NlqTranslationInput<JSONArray, InternalDataSchemaContext>;
export type HighlightsInput = NlqTranslationInput<JSONArray, InternalDataSchemaContext>;
export type MeasuresFunctionCallInput = NlqTranslationInput<FunctionCall[], InternalDataSchemaContext>;
export type FiltersFunctionCallInput = NlqTranslationInput<FunctionCall[], InternalDataSchemaContext>;
export type HighlightsFunctionCallInput = NlqTranslationInput<FunctionCall[], InternalDataSchemaContext>;
export type NodeInput = NlqTranslationInput<FunctionCall, FunctionContext>;
export type ArgInput = NlqTranslationInput<Arg, ArgContext>;
/**
 * Custom processor function signature.
 *
 * Implementations must not mutate `processedArgs`. Returns the argument list to pass to
 * `executeFunction`—typically the same array reference when only validating, or a new array when
 * normalizing or replacing nested values.
 */
export type CustomFunctionProcessor = (processedArgs: ProcessedArg[], context: FunctionContext) => ProcessedArg[];
/**
 * Type guard: value is a non-null object (Record<string, unknown>).
 * @internal
 */
export declare function isRecordStringUnknown(value: unknown): value is Record<string, unknown>;
export declare function isFunctionCall(value: unknown): value is FunctionCall;
export declare function isFunctionCallArray(value: JSONArray): value is FunctionCall[];
export declare function isFilterElement(arg: QueryElement): arg is Filter;
export declare function isFilterRelationsElement(arg: QueryElement): arg is FilterRelations;
export declare function isMeasureElement(arg: QueryElement): arg is Measure;
export declare function isStringArray(value: JSONArray): value is string[];
/**
 * Enriched dimension translation result. Style uses CategoryStyle (same as StyledColumn).
 *
 * @internal
 */
export type DimensionTranslationItem = {
    attribute: Attribute;
    style?: CategoryStyle;
};
/**
 * Enriched measure translation result. Style uses ValueStyle & SeriesStyle (same as StyledMeasureColumn).
 *
 * @internal
 */
export type MeasureTranslationItem = {
    measure: Measure;
    style?: ValueStyle & SeriesStyle;
};
/**
 * JSON-facing type for a styled dimension/attribute.
 * Reusable for query JSON and future chart JSON (translateChartFromJSON).
 *
 * @internal
 */
export interface StyledColumnJSON extends CategoryStyle {
    /** Attribute reference (composeCode), e.g. "DM.Commerce.Gender" */
    column: string;
}
/**
 * JSON-facing type for a styled measure.
 * Reusable for query JSON and future chart JSON (translateChartFromJSON).
 *
 * @internal
 */
export interface StyledMeasureColumnJSON extends ValueStyle, SeriesStyle {
    /** Measure definition (function/args), e.g. { function: "measureFactory.sum", args: [...] } */
    column: FunctionCall;
}
/**
 * Dimension item in query JSON: plain composeCode string or styled column.
 *
 * @internal
 */
export type DimensionItemJSON = string | StyledColumnJSON;
/**
 * Measure item in query JSON: plain function call or styled measure.
 *
 * @internal
 */
export type MeasureItemJSON = FunctionCall | StyledMeasureColumnJSON;
/**
 * Type guard: value is StyledColumnJSON (object with column, not a FunctionCall).
 *
 * @internal
 */
export declare function isStyledColumnJSON(value: unknown): value is StyledColumnJSON;
/**
 * Type guard: value is StyledMeasureColumnJSON (object with column containing a measure definition).
 *
 * @internal
 */
export declare function isStyledMeasureColumnJSON(value: unknown): value is StyledMeasureColumnJSON;
/**
 * JSON representation of chart data options.
 * Maps axis names to arrays of dimension or measure items.
 * Supports all chart types (cartesian, categorical, scatter, etc.).
 *
 * @internal
 */
export interface DataOptionsJSON {
    category?: DimensionItemJSON[];
    /** Array for cartesian/categorical; single for calendar-heatmap */
    value?: MeasureItemJSON[] | MeasureItemJSON;
    breakBy?: DimensionItemJSON[];
    x?: DimensionItemJSON | MeasureItemJSON;
    y?: DimensionItemJSON | MeasureItemJSON;
    breakByPoint?: DimensionItemJSON;
    breakByColor?: DimensionItemJSON | MeasureItemJSON;
    size?: MeasureItemJSON;
    boxType?: MeasureItemJSON;
    outliers?: MeasureItemJSON[];
    geo?: DimensionItemJSON[];
    colorBy?: MeasureItemJSON;
    details?: DimensionItemJSON;
    color?: MeasureItemJSON[];
    date?: DimensionItemJSON;
    columns?: (DimensionItemJSON | MeasureItemJSON)[];
    rows?: DimensionItemJSON[];
    values?: MeasureItemJSON[];
    secondary?: MeasureItemJSON[];
    min?: MeasureItemJSON[];
    max?: MeasureItemJSON[];
}
/**
 * JSON representation of a chart configuration from NLQ API.
 * Matches the structure returned by NLQ v3 for chart recommendations.
 * Reusable for chart JSON translation (translateChartFromJSON/translateChartToJSON).
 *
 * @internal
 */
export interface ChartJSON {
    /** Chart type (e.g., 'column', 'line', 'bar', 'pie', 'scatter') */
    chartType: string;
    /** Data options mapping chart axes to dimensions/measures */
    dataOptions: DataOptionsJSON;
    /** Optional style options for chart appearance (colors, legend, axes, etc.) */
    styleOptions?: Record<string, unknown>;
    /** Optional filters to apply to the chart data */
    filters?: FunctionCall[];
    /** Optional highlights (filter criteria) to apply to the chart */
    highlights?: FunctionCall[];
}
/**
 * Input type for chart translation (JSON → CSDK).
 * Combines chartJSON with data schema context.
 *
 * @internal
 */
export type ChartInput = NlqTranslationInput<ChartJSON, DataSchemaContext>;
/**
 * JSON representation of pivot table data options.
 *
 * @internal
 */
export interface PivotTableDataOptionsJSON {
    rows?: DimensionItemJSON[];
    columns?: DimensionItemJSON[];
    values?: MeasureItemJSON[];
    grandTotals?: PivotGrandTotals;
}
/**
 * JSON representation of pivot table config from NLQ API.
 *
 * @internal
 */
export interface PivotTableJSON {
    dataOptions: PivotTableDataOptionsJSON;
    styleOptions?: PivotTableStyleOptions;
    filters?: FunctionCall[];
    highlights?: FunctionCall[];
}
/**
 * Input type for pivot table translation (JSON → CSDK).
 *
 * @internal
 */
export type PivotTableInput = NlqTranslationInput<PivotTableJSON, DataSchemaContext>;
/**
 * Mirrors `WithCommonWidgetProps` for the JSON layer
 */
type WithCommonWidgetJSON<Base, Type extends WidgetType> = Base & {
    widgetType: Type;
    readonly id: string;
};
/**
 * Data source in NLQ JSON — title only. Full JAQL details live in {@link DataSchemaContext}.
 *
 * @internal
 */
export type DataSourceJSON = string;
/**
 * JSON representation of a chart widget
 *
 * @internal
 */
export type ChartWidgetJSON = ChartJSON & {
    title?: string;
    description?: string;
    dataSource?: DataSourceJSON;
    config?: WidgetConfig;
    highlightSelectionDisabled?: boolean;
};
/**
 * JSON representation of a pivot table widget.
 *
 * @internal
 */
export type PivotTableWidgetJSON = PivotTableJSON & {
    title?: string;
    description?: string;
    dataSource?: DataSourceJSON;
    config?: WidgetConfig;
};
/**
 * JSON representation of a text widget
 *
 * @internal
 */
export type TextWidgetJSON = {
    styleOptions: TextWidgetStyleOptions;
    config?: WidgetConfig;
};
/**
 * JSON representation of a custom/plugin widget payload.
 * `dataOptions` is passed through as opaque JSON — `GenericDataOptions` cannot be reliably
 * round-tripped without custom-widget-specific schema knowledge.
 * Only `filters` and `highlights` are translated; all other fields are pass-through.
 * `widgetType` and `id` are added on `WidgetJSON` via `WithCommonWidgetJSON`.
 *
 * @internal
 */
export type CustomWidgetJSON = {
    customWidgetType: string;
    title?: string;
    description?: string;
    dataSource?: DataSourceJSON;
    config?: WidgetConfig;
    filters?: FunctionCall[];
    highlights?: FunctionCall[];
    /** Opaque pass-through — GenericDataOptions serialized as plain JSON */
    dataOptions?: Record<string, unknown>;
    styleOptions?: CustomWidgetStyleOptions;
    customOptions?: Record<string, unknown>;
};
/**
 * Dashboard-level options for a specific widget in NLQ JSON.
 * Excludes non-JSON-safe fields such as `jtdConfig` (Map / Filter objects).
 *
 * @internal
 */
export type SpecificWidgetOptionsJSON = {
    filtersOptions?: CommonFiltersOptions;
    partialDtoOptions?: {
        options?: Record<string, unknown>;
        style?: Record<string, unknown>;
    };
};
/**
 * Widget options map for NLQ dashboard JSON.
 *
 * @internal
 */
export type WidgetsOptionsJSON = Record<string, SpecificWidgetOptionsJSON>;
/**
 * Discriminated union of all NLQ widget JSON representations.
 * Mirrors the `WidgetProps` discriminated union in serializable JSON form.
 *
 * @internal
 */
export type WidgetJSON = WithCommonWidgetJSON<ChartWidgetJSON, 'chart'> | WithCommonWidgetJSON<PivotTableWidgetJSON, 'pivot'> | WithCommonWidgetJSON<TextWidgetJSON, 'text'> | WithCommonWidgetJSON<CustomWidgetJSON, 'custom'>;
/**
 * JSON representation of a dashboard.
 *
 * @internal
 */
export interface DashboardJSON {
    id?: string;
    title?: string;
    filters?: FunctionCall[];
    widgets: WidgetJSON[];
    layoutOptions?: DashboardLayoutOptions;
    config?: DashboardConfig;
    /** Data source title only — schema details live in {@link DataSchemaContext}. */
    defaultDataSource?: DataSourceJSON;
    styleOptions?: DashboardStyleOptions;
    widgetsOptions?: WidgetsOptionsJSON;
}
/**
 * Input type for widget translation (JSON → CSDK).
 *
 * @internal
 */
export type WidgetInput = NlqTranslationInput<WidgetJSON, DataSchemaContext>;
/**
 * Input type for dashboard translation (JSON → CSDK).
 *
 * @internal
 */
export type DashboardInput = NlqTranslationInput<DashboardJSON, DataSchemaContext>;
