import type { AdditionalMetric, currencies, DefaultTimeDimension, LightdashProjectConfig } from '..';
import { type AnyType } from './any';
import { type MetricFilterRule } from './filter';
import type { TimeFrames } from './timeFrames';
export declare enum Compact {
    AUTO = "auto",
    THOUSANDS = "thousands",
    MILLIONS = "millions",
    BILLIONS = "billions",
    TRILLIONS = "trillions",
    KILOBYTES = "kilobytes",
    MEGABYTES = "megabytes",
    GIGABYTES = "gigabytes",
    TERABYTES = "terabytes",
    PETABYTES = "petabytes",
    KIBIBYTES = "kibibytes",
    MEBIBYTES = "mebibytes",
    GIBIBYTES = "gibibytes",
    TEBIBYTES = "tebibytes",
    PEBIBYTES = "pebibytes"
}
declare const CompactAlias: readonly ["K", "thousand", "M", "million", "B", "billion", "T", "trillion", "KB", "kilobyte", "MB", "megabyte", "GB", "gigabyte", "TB", "terabyte", "PB", "petabyte", "KiB", "kibibyte", "MiB", "mebibyte", "GiB", "gibibyte", "TiB", "tebibyte", "PiB", "pebibyte"];
export declare enum NumberSeparator {
    DEFAULT = "default",// Default separator
    COMMA_PERIOD = "commaPeriod",// 100,000.00
    SPACE_PERIOD = "spacePeriod",// 100 000.00
    PERIOD_COMMA = "periodComma",// 100.000,00
    NO_SEPARATOR_PERIOD = "noSeparatorPeriod",// 100000.00
    APOSTROPHE_PERIOD = "apostrophePeriod"
}
type CompactConfig = {
    compact: Compact;
    alias: Array<(typeof CompactAlias)[number]>;
    orderOfMagnitude: number;
    convertFn: (value: number) => number;
    label: string;
    suffix: string;
};
export type CompactOrAlias = Compact | (typeof CompactAlias)[number];
export declare const CompactConfigMap: Record<Compact, CompactConfig>;
export declare function findCompactConfig(compactOrAlias: CompactOrAlias): CompactConfig | undefined;
export declare enum BinType {
    FIXED_NUMBER = "fixed_number",
    FIXED_WIDTH = "fixed_width",
    CUSTOM_RANGE = "custom_range",
    CUSTOM_GROUP = "custom_group"
}
export type BinRange = {
    /** Start value for this bin range (undefined for the first range) */
    from: number | undefined;
    /** End value for this bin range (undefined for the last range) */
    to: number | undefined;
};
export declare enum GroupValueMatchType {
    EXACT = "exact",
    STARTS_WITH = "startsWith",
    ENDS_WITH = "endsWith",
    INCLUDES = "includes"
}
export type GroupValueRule = {
    matchType: GroupValueMatchType;
    value: string;
};
export type BinGroup = {
    /** Display name for this group (e.g. "North America") */
    name: string;
    /** Rules that match values into this group */
    values: GroupValueRule[];
};
export declare enum CustomDimensionType {
    BIN = "bin",
    SQL = "sql"
}
export interface BaseCustomDimension {
    /** Unique identifier for the custom dimension */
    id: string;
    /** Display name for the custom dimension */
    name: string;
    /** Table this custom dimension belongs to */
    table: string;
    /** Type of custom dimension (bin or sql) */
    type: CustomDimensionType;
}
interface BaseCustomBinDimension extends BaseCustomDimension {
    type: CustomDimensionType.BIN;
    /** Field ID of the parent dimension to bin */
    dimensionId: FieldId;
}
export interface FixedNumberBinDimension extends BaseCustomBinDimension {
    binType: BinType.FIXED_NUMBER;
    binNumber: number;
}
export interface FixedWidthBinDimension extends BaseCustomBinDimension {
    binType: BinType.FIXED_WIDTH;
    binWidth: number;
}
export interface CustomRangeBinDimension extends BaseCustomBinDimension {
    binType: BinType.CUSTOM_RANGE;
    customRange: BinRange[];
}
export interface CustomGroupBinDimension extends BaseCustomBinDimension {
    binType: BinType.CUSTOM_GROUP;
    customGroups: BinGroup[];
}
export type CustomBinDimension = FixedNumberBinDimension | FixedWidthBinDimension | CustomRangeBinDimension | CustomGroupBinDimension;
export interface CustomSqlDimension extends BaseCustomDimension {
    type: CustomDimensionType.SQL;
    /** SQL expression for the custom dimension */
    sql: string;
    /** Data type of the dimension result */
    dimensionType: DimensionType;
}
export type CustomDimension = CustomBinDimension | CustomSqlDimension;
export declare const isCustomDimension: (value: AnyType) => value is CustomDimension;
export declare const isCustomBinDimension: (value: AnyType) => value is CustomBinDimension;
export declare const isCustomSqlDimension: (value: AnyType) => value is CustomSqlDimension;
export type CompiledCustomSqlDimension = CustomSqlDimension & {
    compiledSql: string;
    tablesReferences: Array<string>;
    parameterReferences?: string[];
};
export type CompiledCustomDimension = CustomBinDimension | CompiledCustomSqlDimension;
export declare const isCompiledCustomSqlDimension: (value: AnyType) => value is CompiledCustomSqlDimension;
export type ItemsMap = Record<string, Field | TableCalculation | CustomDimension | Metric>;
export type Item = ItemsMap[string];
export interface CustomFormat {
    /** Format type */
    type: CustomFormatType;
    /** Number of decimal places */
    round?: number | undefined;
    /** Number separator style */
    separator?: NumberSeparator;
    /** Currency code (e.g., USD, GBP, EUR) */
    currency?: (typeof currencies)[number] | undefined;
    /** Compact format for large numbers (K, M, B, T) or byte units */
    compact?: CompactOrAlias | undefined;
    /** Prefix to prepend to formatted values */
    prefix?: string | undefined;
    /** Suffix to append to formatted values */
    suffix?: string | undefined;
    /** Time interval for date formatting */
    timeInterval?: TimeFrames;
    /** Custom format string */
    custom?: string | undefined;
}
export declare enum CustomFormatType {
    DEFAULT = "default",
    PERCENT = "percent",
    CURRENCY = "currency",
    NUMBER = "number",
    ID = "id",
    DATE = "date",
    TIMESTAMP = "timestamp",
    BYTES_SI = "bytes_si",
    BYTES_IEC = "bytes_iec",
    CUSTOM = "custom"
}
export declare enum TableCalculationType {
    NUMBER = "number",
    STRING = "string",
    DATE = "date",
    TIMESTAMP = "timestamp",
    BOOLEAN = "boolean"
}
export declare enum WindowFunctionType {
    ROW_NUMBER = "row_number",
    PERCENT_RANK = "percent_rank",
    CUME_DIST = "cume_dist",
    RANK = "rank",
    SUM = "sum",
    AVG = "avg",
    COUNT = "count",
    MIN = "min",
    MAX = "max"
}
export declare const nullaryWindowFunctions: WindowFunctionType[];
export declare const unaryWindowFunctions: WindowFunctionType[];
export declare enum FrameType {
    ROWS = "rows",
    RANGE = "range"
}
export declare enum FrameBoundaryType {
    UNBOUNDED_PRECEDING = "unbounded_preceding",
    PRECEDING = "preceding",
    CURRENT_ROW = "current_row",
    FOLLOWING = "following",
    UNBOUNDED_FOLLOWING = "unbounded_following"
}
export type FrameBoundary = {
    /** Boundary type */
    type: FrameBoundaryType;
    /** Offset for PRECEDING/FOLLOWING */
    offset?: number;
};
export type FrameClause = {
    /** Type of frame (ROWS or RANGE) */
    frameType: FrameType;
    /** Start boundary of the frame */
    start?: FrameBoundary;
    /** End boundary of the frame */
    end: FrameBoundary;
};
export declare enum TableCalculationTemplateType {
    PERCENT_CHANGE_FROM_PREVIOUS = "percent_change_from_previous",
    PERCENT_OF_PREVIOUS_VALUE = "percent_of_previous_value",
    PERCENT_OF_COLUMN_TOTAL = "percent_of_column_total",
    RANK_IN_COLUMN = "rank_in_column",
    RUNNING_TOTAL = "running_total",
    WINDOW_FUNCTION = "window_function"
}
export type TableCalculationTemplate = {
    /** Type of template calculation */
    type: TableCalculationTemplateType.PERCENT_CHANGE_FROM_PREVIOUS;
    /** Field ID to apply the template to */
    fieldId: string;
    /** Fields to order by for window functions */
    orderBy: {
        fieldId: string;
        order: 'asc' | 'desc' | null;
    }[];
    partitionBy?: string[];
} | {
    /** Type of template calculation */
    type: TableCalculationTemplateType.PERCENT_OF_PREVIOUS_VALUE;
    /** Field ID to apply the template to */
    fieldId: string;
    /** Fields to order by for window functions */
    orderBy: {
        fieldId: string;
        order: 'asc' | 'desc' | null;
    }[];
    partitionBy?: string[];
} | {
    /** Type of template calculation */
    type: TableCalculationTemplateType.PERCENT_OF_COLUMN_TOTAL;
    /** Field ID to apply the template to */
    fieldId: string;
    /** Fields to partition by */
    partitionBy?: string[];
} | {
    /** Type of template calculation */
    type: TableCalculationTemplateType.RANK_IN_COLUMN;
    /** Field ID to apply the template to */
    fieldId: string;
} | {
    /** Type of template calculation */
    type: TableCalculationTemplateType.RUNNING_TOTAL;
    /** Field ID to apply the template to */
    fieldId: string;
} | {
    /** Type of template calculation */
    type: TableCalculationTemplateType.WINDOW_FUNCTION;
    /** Window function type */
    windowFunction: WindowFunctionType;
    /** Field ID to apply the template to */
    fieldId: string | null;
    /** Fields to order by for window functions */
    orderBy: {
        fieldId: string;
        order: 'asc' | 'desc' | null;
    }[];
    /** Fields to partition by for window functions */
    partitionBy: string[];
    /** Frame clause for window functions */
    frame?: FrameClause;
};
export declare enum TableCalculationTotalMode {
    /** Apply the calculation to the aggregated totals row (default) — right for ratios */
    FORMULA = "formula",
    /** Sum the calculation's row-level values — right for row-level transformations */
    SUM_OF_ROWS = "sum_of_rows",
    /** Show no total for this calculation */
    NONE = "none"
}
export type TableCalculationBase = {
    /** Display order index */
    index?: number;
    /** Internal name of the table calculation */
    name: string;
    /** Display name shown in the UI */
    displayName: string;
    /** Formatting options for the calculation */
    format?: CustomFormat;
    /** Data type of the calculation result */
    type?: TableCalculationType;
    /** How column totals are computed for this calculation */
    totalMode?: TableCalculationTotalMode;
};
export type SqlTableCalculation = TableCalculationBase & {
    /** SQL expression for the calculation (can reference fields with ${table.field}) */
    sql: string;
};
export type TemplateTableCalculation = TableCalculationBase & {
    /** Template-based calculation (alternative to sql) */
    template: TableCalculationTemplate;
};
export type FormulaTableCalculation = TableCalculationBase & {
    /** Spreadsheet-like formula compiled to SQL at query time */
    formula: string;
};
export type TableCalculation = SqlTableCalculation | TemplateTableCalculation | FormulaTableCalculation;
export type TableCalculationMetadata = {
    oldName: string;
    name: string;
};
export declare enum FieldType {
    METRIC = "metric",
    DIMENSION = "dimension"
}
export declare const isTableCalculation: (item: ItemsMap[string] | AdditionalMetric | Pick<Field, "table" | "name">) => item is TableCalculation;
export declare const isSqlTableCalculation: (calc: TableCalculation) => calc is SqlTableCalculation;
export declare const isTemplateTableCalculation: (calc: TableCalculation) => calc is TemplateTableCalculation;
export declare const isFormulaTableCalculation: (calc: TableCalculation) => calc is FormulaTableCalculation;
export type CompiledTableCalculation = TableCalculation & {
    compiledSql: string;
    dependsOn: string[];
};
export type FieldUrl = {
    url: string;
    label: string;
};
export interface Field {
    fieldType: FieldType;
    type: string;
    name: string;
    label: string;
    table: string;
    tableLabel: string;
    sql: string;
    description?: string;
    source?: Source | undefined;
    hidden: boolean;
    compact?: CompactOrAlias;
    round?: number;
    format?: Format | string;
    /**
     * Number separator style for grouping/decimal characters. Composes with
     * `format` (including ECMA-376 expressions) and `formatOptions` — it only
     * controls the separator characters, not the format shape.
     */
    separator?: NumberSeparator;
    /**
     * @deprecated Use groups property instead.
     */
    groupLabel?: string;
    groups?: string[];
    urls?: FieldUrl[];
    index?: number;
    tags?: string[];
    parameterReferences?: string[];
}
export declare const isField: (field: AnyType) => field is Field;
export type FieldId = string;
export declare const convertFieldRefToFieldId: (fieldRef: string, fallbackTableName?: string) => string;
export type Source = {
    path: string;
    range: {
        start: SourcePosition;
        end: SourcePosition;
    };
    highlight?: {
        start: SourcePosition;
        end: SourcePosition;
    };
    content: string;
};
type SourcePosition = {
    line: number;
    character: number;
};
export declare enum DimensionType {
    STRING = "string",
    NUMBER = "number",
    TIMESTAMP = "timestamp",
    DATE = "date",
    BOOLEAN = "boolean"
}
/**
 * Whether a TIMESTAMP column stores an instant ('aware') or a bare wall clock
 * ('naive'). Absent means unknown — never assume 'aware' for a missing value.
 */
export type TimestampDomain = 'aware' | 'naive';
export declare const isTimestampDomain: (value: unknown) => value is TimestampDomain;
export type FilterAutocompleteValue = {
    value: string;
    label?: string;
};
export type FilterAutocompleteConfig = {
    values?: FilterAutocompleteValue[];
    fetchFromWarehouse: boolean;
    labelDimension?: string;
};
/**
 * Whether a dimension's curated `filter_autocomplete` values can answer a value
 * search without querying the warehouse. Mirrors the Explore filter UI
 * (`useFieldValues`): always use curated values when the warehouse fetch is
 * turned off; otherwise only as the fast path for an empty ("list all") search.
 */
export declare const shouldUseStaticFilterAutocomplete: (filterAutocomplete: FilterAutocompleteConfig | undefined, search: string) => boolean;
export declare const filterStaticFilterAutocompleteValues: (values: FilterAutocompleteValue[], search: string) => string[];
export interface Dimension extends Field {
    fieldType: FieldType.DIMENSION;
    type: DimensionType;
    /**
     * @deprecated Use groups property instead.
     */
    group?: string;
    requiredAttributes?: Record<string, string | string[]>;
    anyAttributes?: Record<string, string | string[]>;
    timeInterval?: TimeFrames;
    /** Overridden display label for this dimension's grain (project
     *  `granularity_labels`); undefined when no override — callers fall back
     *  to `timeFrameConfigs[timeInterval].getLabel()`. */
    timeIntervalLabel?: string;
    timeIntervalBaseDimensionName?: string;
    timeIntervalBaseDimensionType?: DimensionType;
    customTimeInterval?: string;
    isAdditionalDimension?: boolean;
    skipTimezoneConversion?: boolean;
    timestampDomain?: TimestampDomain;
    colors?: Record<string, string>;
    isIntervalBase?: boolean;
    aiHint?: string | string[];
    formatOptions?: CustomFormat;
    caseSensitive?: boolean;
    image?: {
        url: string;
        width?: number;
        height?: number;
        fit?: string;
    };
    richText?: string;
    filterAutocomplete?: FilterAutocompleteConfig;
    spotlight?: {
        filterBy?: boolean;
        segmentBy?: boolean;
    };
}
/**
 * Error information stored on a field when compilation fails but
 * partial compilation mode is enabled.
 */
export type FieldCompilationError = {
    message: string;
};
type CompiledProperties = {
    compiledSql: string;
    tablesReferences: Array<string> | undefined;
    tablesRequiredAttributes?: Record<string, Record<string, string | string[]>>;
    tablesAnyAttributes?: Record<string, Record<string, string | string[]>>;
    /**
     * When partial compilation mode is enabled, fields that fail to compile
     * will have this property set instead of causing the entire explore to fail.
     */
    compilationError?: FieldCompilationError;
    compiledValueSql?: string;
    compiledDistinctKeys?: string[];
    compiledRelativeDateFilters?: CompiledMetricRelativeDateFilter[];
    compiledTimestampFilters?: CompiledMetricTimestampFilter[];
};
export type CompiledMetricRelativeDateFilter = {
    id: string;
    fieldId: string;
    compiledSql: string;
};
export type CompiledMetricTimestampFilter = CompiledMetricRelativeDateFilter;
export type CompiledDimension = Dimension & CompiledProperties;
export type CompiledMetric = Metric & CompiledProperties;
/**
 * Type guard to check if a compiled field has a compilation error.
 */
export declare const hasFieldCompilationError: (field: CompiledDimension | CompiledMetric) => boolean;
export type CompiledField = CompiledDimension | CompiledMetric;
export declare const isDimension: (field: ItemsMap[string] | AdditionalMetric | undefined) => field is Dimension;
export declare const isTimeBasedDimension: (item: ItemsMap[string] | AdditionalMetric | undefined) => item is Dimension;
export interface FilterableDimension extends Dimension {
    type: DimensionType.STRING | DimensionType.NUMBER | DimensionType.DATE | DimensionType.TIMESTAMP | DimensionType.BOOLEAN;
}
export type FieldRef = string;
export declare const getFieldRef: (field: Pick<Field, "table" | "name">) => FieldRef;
export declare const getFieldLabel: (field: Field) => string;
export declare enum MetricType {
    PERCENTILE = "percentile",
    AVERAGE = "average",
    COUNT = "count",
    COUNT_DISTINCT = "count_distinct",
    SUM = "sum",
    SUM_DISTINCT = "sum_distinct",
    AVERAGE_DISTINCT = "average_distinct",
    MIN = "min",
    MAX = "max",
    PERCENT_OF_PREVIOUS = "percent_of_previous",
    PERCENT_OF_TOTAL = "percent_of_total",
    RUNNING_TOTAL = "running_total",
    NUMBER = "number",
    MEDIAN = "median",
    STRING = "string",
    DATE = "date",
    TIMESTAMP = "timestamp",
    BOOLEAN = "boolean"
}
export declare enum Format {
    KM = "km",
    MI = "mi",
    SI = "si",
    USD = "usd",
    GBP = "gbp",
    EUR = "eur",
    JPY = "jpy",
    DKK = "dkk",
    ID = "id",
    PERCENT = "percent"
}
export declare const isFormat: (value: string | undefined) => value is Format;
export declare const parseMetricType: (metricType: string) => MetricType;
export declare const PostCalculationMetricTypes: MetricType[];
export declare const isMetric: (field: ItemsMap[string] | AdditionalMetric | undefined) => field is Metric;
export declare const isNonAggregateMetric: (field: Field) => boolean;
export declare const AggregateMetricTypes: readonly [MetricType.SUM, MetricType.COUNT, MetricType.COUNT_DISTINCT, MetricType.AVERAGE, MetricType.MIN, MetricType.MAX, MetricType.MEDIAN, MetricType.PERCENTILE];
export declare const isAggregateMetricType: (type: MetricType) => boolean;
export declare const isNonAggregateMetricType: (type: MetricType) => boolean;
export declare const isPostCalculationMetricType: (type: MetricType) => boolean;
export declare const isPostCalculationMetric: (field: Field) => boolean;
export declare const isCompiledMetric: (field: ItemsMap[string] | AdditionalMetric | undefined) => field is CompiledMetric;
export interface Metric extends Field {
    fieldType: FieldType.METRIC;
    type: MetricType;
    showUnderlyingValues?: string[];
    filters?: MetricFilterRule[];
    percentile?: number;
    distinctKeys?: string[];
    formatOptions?: CustomFormat;
    dimensionReference?: string;
    baseDimensionType?: DimensionType;
    baseDimensionTimeInterval?: TimeFrames;
    requiredAttributes?: Record<string, string | string[]>;
    anyAttributes?: Record<string, string | string[]>;
    defaultTimeDimension?: DefaultTimeDimension;
    spotlight?: {
        visibility: LightdashProjectConfig['spotlight']['default_visibility'];
        categories?: string[];
        filterBy?: string[];
        segmentBy?: string[];
        defaultSegment?: string;
        defaultFilter?: MetricFilterRule;
        owner?: string;
    };
    drivers?: string[];
    aiHint?: string | string[];
    richText?: string;
}
export declare const getMinMaxBaseDimensionMetadata: (metricType: MetricType, base: {
    type: DimensionType;
    timeInterval?: TimeFrames;
} | undefined) => Pick<Metric, "baseDimensionType" | "baseDimensionTimeInterval">;
export declare const isFilterableDimension: (dimension: Dimension | undefined) => dimension is FilterableDimension;
export type DashboardFilterableField = FilterableDimension | Metric;
export type FilterableField = TableCalculation | Metric | FilterableDimension | CustomSqlDimension;
export declare const isFilterableField: (field: Dimension | ItemsMap[string]) => field is FilterableField;
export type FilterableItem = FilterableField;
export declare const isFilterableItem: (item: ItemsMap[string] | TableCalculation) => item is FilterableItem;
export declare const defaultSql: (columnName: string) => string;
export declare const capitalize: (word: string) => string;
export declare const friendlyName: (text: string) => string;
export declare const isSummable: (item: Item | undefined) => boolean;
export declare const IECByteCompacts: Compact[];
export declare function getCompactOptionsForFormatType(type: CustomFormatType): Compact[];
export {};
//# sourceMappingURL=field.d.ts.map