import { type AnyType } from './any';
import { type DateZoom } from './api/paginatedQuery';
import { type CompactOrAlias, type CompiledCustomDimension, type CompiledDimension, type CompiledMetric, type CompiledTableCalculation, type CustomDimension, type CustomFormat, type Dimension, type FieldId, type Format, type Metric, type MetricType, type NumberSeparator, type TableCalculation } from './field';
import { type Filters, type MetricFilterRule } from './filter';
import { type TimeFrames } from './timeFrames';
export interface AdditionalMetric {
    /** Display label for the metric */
    label?: string;
    /** Aggregation type */
    type: MetricType;
    /** Description of what the metric measures */
    description?: string;
    /** SQL expression (e.g., ${TABLE}.column_name) */
    sql: string;
    /** Whether the metric is hidden from users */
    hidden?: boolean;
    /** Number of decimal places */
    round?: number;
    /** Compact format for large numbers */
    compact?: CompactOrAlias;
    /** Format string (legacy format specification) */
    format?: Format | string;
    /** Number separator style for grouping/decimal characters */
    separator?: NumberSeparator;
    /** Table name the metric belongs to */
    table: string;
    /** Internal name of the metric */
    name: string;
    /** Display order index */
    index?: number;
    /** Filters to apply to this metric */
    filters?: MetricFilterRule[];
    /** Name of the base dimension/column this metric aggregates */
    baseDimensionName?: string;
    /** Name of the explore metric this metric was cloned from */
    baseMetricName?: string;
    /** Unique identifier for the metric */
    uuid?: string | null;
    /** Percentile value for percentile metrics */
    percentile?: number;
    distinctKeys?: string[];
    /** Formatting configuration */
    formatOptions?: CustomFormat;
    /**
     * Optional marker for metrics generated by the system.
     * Currently used for Period-over-Period (PoP) previous-period metrics.
     */
    generationType?: 'periodOverPeriod';
    /**
     * For PoP-generated metrics, the base metric id that this metric is derived from.
     */
    baseMetricId?: FieldId;
    /**
     * For PoP-generated metrics, the time dimension id used for the comparison.
     */
    timeDimensionId?: FieldId;
    /**
     * For PoP-generated metrics, the granularity used for the comparison.
     */
    granularity?: TimeFrames;
    /**
     * For PoP-generated metrics, the number of periods to offset by (>= 1).
     */
    periodOffset?: number;
}
export declare const isAdditionalMetric: (value: AnyType) => value is AdditionalMetric;
export interface PeriodOverPeriodAdditionalMetric extends AdditionalMetric {
    generationType: 'periodOverPeriod';
    /**
     * The base metric id that this metric is the previous-period version of.
     * This avoids relying on suffix parsing to establish the relationship.
     */
    baseMetricId: FieldId;
    /**
     * The time dimension field id used for the comparison.
     */
    timeDimensionId: FieldId;
    /**
     * Granularity for the comparison (derived from the chosen time dimension).
     */
    granularity: TimeFrames;
    /**
     * Number of periods to offset by (>= 1).
     */
    periodOffset: number;
}
type PeriodOverPeriodGeneratedMetricMetadata = {
    generationType: 'periodOverPeriod';
    baseMetricId: FieldId;
    timeDimensionId: FieldId;
    granularity: TimeFrames;
    periodOffset: number;
};
/**
 * Type guard for Period-over-Period generated metric metadata.
 *
 * Note: This metadata can exist on both `AdditionalMetric` objects (query-time)
 * and the converted `Metric` objects in `ItemsMap` (render-time), since we
 * preserve these fields during conversion.
 */
export declare const hasPeriodOverPeriodGeneratedMetricMetadata: (value: AnyType) => value is PeriodOverPeriodGeneratedMetricMetadata;
export declare const isPeriodOverPeriodAdditionalMetric: (value: AnyType) => value is PeriodOverPeriodAdditionalMetric;
export declare const hasFormatOptions: (value: AnyType) => value is {
    formatOptions: CustomFormat;
};
export declare const getCustomMetricDimensionId: (metric: AdditionalMetric) => string;
export type MetricOverrides = {
    [key: string]: Pick<Metric, 'formatOptions'>;
};
export type DimensionOverrides = {
    [key: string]: Pick<Dimension, 'formatOptions'>;
};
export type MetricQuery = {
    /** The name of the explore to query */
    exploreName: string;
    /** List of dimension field IDs to include */
    dimensions: FieldId[];
    /** List of metric field IDs to include */
    metrics: FieldId[];
    /** Filter rules to apply to the query */
    filters: Filters;
    /** Sort configuration for query results */
    sorts: SortField[];
    /** Maximum number of rows to return */
    limit: number;
    /** Custom calculations to perform on query results */
    tableCalculations: TableCalculation[];
    /** Custom metrics defined inline (ad-hoc metrics not in the dbt model) */
    additionalMetrics?: AdditionalMetric[];
    /** Custom dimensions defined inline */
    customDimensions?: CustomDimension[];
    /** Override formatting options for existing metrics */
    metricOverrides?: MetricOverrides;
    /** Override formatting options for existing dimensions */
    dimensionOverrides?: DimensionOverrides;
    /** Timezone for date/time values (e.g., 'America/Los_Angeles', 'UTC') */
    timezone?: string;
    /** Dimension field IDs used as pivot columns (from chart's pivotConfig.columns).
     * Used by row_total() to determine non-pivot dimensions for GROUP BY. */
    pivotDimensions?: FieldId[];
    metadata?: {
        hasADateDimension: Pick<CompiledDimension, 'label' | 'name' | 'table'>;
    };
};
export type CompiledMetricQuery = Omit<MetricQuery, 'customDimensions'> & {
    compiledTableCalculations: CompiledTableCalculation[];
    compiledAdditionalMetrics: CompiledMetric[];
    compiledCustomDimensions: CompiledCustomDimension[];
};
/**
 * Coordinates of a single pivot column, used to anchor a row sort to that
 * specific column when results are pivoted.
 */
export type PivotSortAnchor = {
    reference: string;
    value: string | number | boolean | null;
};
export type SortField = {
    /** Field ID to sort by */
    fieldId: string;
    /** Sort in descending order */
    descending: boolean;
    /** Sort null values first */
    nullsFirst?: boolean;
    /** Pins the row-sort anchor to a specific pivot column. Ignored for non-pivoted results. */
    pivotValues?: PivotSortAnchor[];
};
export declare const getAdditionalMetricLabel: (item: AdditionalMetric) => string;
type FilterGroupResponse = {
    id: string;
    or: AnyType[];
} | {
    id: string;
    and: AnyType[];
};
export type FiltersResponse = {
    dimensions?: FilterGroupResponse;
    metrics?: FilterGroupResponse;
    tableCalculations?: FilterGroupResponse;
};
export type MetricQueryResponse = {
    exploreName: string;
    dimensions: FieldId[];
    metrics: FieldId[];
    filters: FiltersResponse;
    sorts: SortField[];
    limit: number;
    tableCalculations: TableCalculation[];
    additionalMetrics?: AdditionalMetric[];
    customDimensions?: CustomDimension[];
    metadata?: {
        hasADateDimension: Pick<CompiledDimension, 'label' | 'name' | 'table'>;
    };
};
export declare const countCustomDimensionsInMetricQuery: (metricQuery: MetricQuery) => {
    numFixedWidthBinCustomDimensions: number;
    numFixedBinsBinCustomDimensions: number;
    numCustomRangeBinCustomDimensions: number;
    numCustomGroupBinCustomDimensions: number;
    numCustomSqlDimensions: number;
};
export declare const hasCustomBinDimension: (metricQuery: MetricQuery | undefined) => boolean | undefined;
export type MetricQueryRequest = {
    exploreName: string;
    dimensions: FieldId[];
    metrics: FieldId[];
    filters: {
        dimensions?: AnyType;
        metrics?: AnyType;
        tableCalculations?: AnyType;
    };
    sorts: SortField[];
    limit: number;
    tableCalculations: TableCalculation[];
    additionalMetrics?: AdditionalMetric[];
    csvLimit?: number;
    customDimensions?: CustomDimension[];
    dateZoom?: DateZoom;
    metadata?: MetricQuery['metadata'];
    timezone?: string;
    pivotDimensions?: FieldId[];
    metricOverrides?: MetricOverrides;
    dimensionOverrides?: DimensionOverrides;
};
export type QueryWarning = {
    message: string;
    fields?: string[];
    tables?: string[];
};
export {};
//# sourceMappingURL=metricQuery.d.ts.map