import type { Tag } from '@malloydata/malloy-tag';
import * as Malloy from '@malloydata/malloy-interfaces';
export type DrillEntry = {
    field: Field;
    value: string | number | boolean | Date | null;
} | {
    where: string;
};
export interface FieldRegistry {
    fieldInstances: Map<string, Field[]>;
    plugins: Map<string, RenderPluginInstance[]>;
}
export declare function getDataTree(result: Malloy.Result, plugins?: RenderPlugin[]): RootCell;
export type Field = ArrayField | RepeatedRecordField | RecordField | NumberField | DateField | JSONField | StringField | TimestampField | BooleanField | SQLNativeField;
export type NestField = RepeatedRecordField | RecordField | ArrayField;
export type RecordOrRepeatedRecordField = RepeatedRecordField | RecordField;
export type BasicAtomicField = NumberField | DateField | JSONField | StringField | TimestampField | BooleanField | SQLNativeField;
export type TimeField = DateField | TimestampField;
export type SortableField = {
    field: Field;
    dir: 'asc' | 'desc' | undefined;
};
type ArrayFieldInfo = Malloy.DimensionInfo & {
    type: Malloy.AtomicTypeWithArrayType;
};
type RepeatedRecordFieldInfo = Malloy.DimensionInfo & {
    type: Malloy.AtomicTypeWithArrayType & {
        element_type: Malloy.AtomicTypeWithRecordType;
    };
};
type RecordFieldInfo = Malloy.DimensionInfo & {
    type: Malloy.AtomicTypeWithRecordType;
};
type NumberFieldInfo = Malloy.DimensionInfo & {
    type: Malloy.AtomicTypeWithNumberType;
};
type DateFieldInfo = Malloy.DimensionInfo & {
    type: Malloy.AtomicTypeWithDateType;
};
type JSONFieldInfo = Malloy.DimensionInfo & {
    type: Malloy.AtomicTypeWithJSONType;
};
type StringFieldInfo = Malloy.DimensionInfo & {
    type: Malloy.AtomicTypeWithStringType;
};
type TimestampFieldInfo = Malloy.DimensionInfo & {
    type: Malloy.AtomicTypeWithTimestampType;
};
type BooleanFieldInfo = Malloy.DimensionInfo & {
    type: Malloy.AtomicTypeWithBooleanType;
};
type SQLNativeFieldInfo = Malloy.DimensionInfo & {
    type: Malloy.AtomicTypeWithSQLNativeType;
};
export declare const Field: {
    from(field: Malloy.DimensionInfo, parent: NestField | undefined, registry?: FieldRegistry): Field;
    isNestField(field: Field): field is NestField;
    pathFromString(path: string): any;
    pathToString(path: string[]): string;
};
type DrillValue = {
    field: Field;
    value: Cell;
} | {
    where: string;
};
export declare function shouldRenderAs(field: Malloy.DimensionInfo, parent: Field | undefined, tagOverride?: Tag): string;
export declare abstract class FieldBase {
    readonly field: Malloy.DimensionInfo;
    readonly parent: NestField | undefined;
    readonly tag: Tag;
    readonly path: string[];
    protected readonly metadataTag: Tag;
    readonly renderAs: string;
    readonly valueSet: Set<string | number | boolean>;
    private _pluginData;
    protected registry?: FieldRegistry;
    registerPluginData<T>(pluginType: string, data: T): void;
    getPluginData<T>(pluginType: string): T | undefined;
    getAllFieldInstances(): Field[];
    getPlugins(): RenderPluginInstance[];
    constructor(field: Malloy.DimensionInfo, parent: NestField | undefined, registry?: FieldRegistry);
    isRoot(): boolean;
    root(): RootField;
    get drillPath(): string[];
    get sourceName(): string;
    get sourceArguments(): Malloy.ParameterValue[] | undefined;
    get name(): string;
    fieldAt(path: string[] | string): Field;
    getParentRecord(levelsUp: number): RecordField;
    get key(): string;
    fieldAtPath(path: string[]): Field;
    registerNullValue(): void;
    get drillFilters(): string[];
    getStableDrillFilter(filter: Tag): Malloy.Filter | undefined;
    get stableDrillFilters(): Malloy.Filter[] | undefined;
    get referenceId(): string | undefined;
    private escapeIdentifier;
    private identifierCode;
    drillExpression(): string;
    wasDimension(): boolean;
    wasCalculation(): boolean;
    isHidden(): boolean;
    get minNumber(): number | undefined;
    get maxNumber(): number | undefined;
    get maxString(): string | undefined;
    asField(): Field;
    isArray(): this is ArrayField;
    isRepeatedRecord(): this is RepeatedRecordField;
    isRecord(): this is RecordField;
    isNumber(): this is NumberField;
    isBoolean(): this is BooleanField;
    isString(): this is StringField;
    isRecordOrRepeatedRecord(): this is RecordOrRepeatedRecordField;
    isDate(): this is DateField;
    isTimestamp(): this is TimestampField;
    isTime(): this is TimeField;
    isSQLNative(): this is SQLNativeField;
    isJSON(): this is JSONField;
    isBasic(): this is BasicAtomicField;
    isNest(): this is NestField;
    getLocationInParent(): any;
    isLastChild(): any;
    isFirstChild(): any;
    pathTo(childField: Field): string;
}
export declare class ArrayField extends FieldBase {
    readonly field: ArrayFieldInfo;
    readonly fields: Field[];
    readonly maxUniqueFieldValueCounts: Map<string, number>;
    readonly eachField: Field;
    constructor(field: ArrayFieldInfo, parent: NestField | undefined, registry?: FieldRegistry);
    get isDrillable(): boolean;
}
export declare class RepeatedRecordField extends ArrayField {
    readonly field: RepeatedRecordFieldInfo;
    readonly fields: Field[];
    maxRecordCount: number;
    constructor(field: RepeatedRecordFieldInfo, parent: NestField | undefined, registry?: FieldRegistry);
    fieldAtPath(path: string[]): Field;
    registerRecordCount(count: number): void;
    registerValueSetSize(fieldName: string, size: number): void;
    private _fieldsWithOrder;
    get fieldsWithOrder(): SortableField[];
}
export declare class RootField extends RepeatedRecordField {
    readonly field: RepeatedRecordFieldInfo;
    readonly modelTag: Tag;
    readonly queryTimezone: string | undefined;
    constructor(field: RepeatedRecordFieldInfo, metadata: {
        modelTag: Tag;
        queryTimezone: string | undefined;
    }, registry?: FieldRegistry);
}
export declare class RecordField extends FieldBase {
    readonly field: RecordFieldInfo;
    readonly fields: Field[];
    readonly fieldsByName: Record<string, Field>;
    readonly maxUniqueFieldValueCounts: Map<string, number>;
    constructor(field: RecordFieldInfo, parent: NestField | undefined, registry?: FieldRegistry);
    fieldAtPath(path: string[]): Field;
    private _fieldsWithOrder;
    get fieldsWithOrder(): SortableField[];
}
export declare class NumberField extends FieldBase {
    readonly field: NumberFieldInfo;
    min: number | undefined;
    max: number | undefined;
    private _maxString;
    constructor(field: NumberFieldInfo, parent: NestField | undefined, registry?: FieldRegistry);
    registerValue(value: number): void;
    fieldAtPath(path: string[]): Field;
    get minNumber(): number | undefined;
    get maxNumber(): number | undefined;
    get maxString(): string | undefined;
}
export declare class DateField extends FieldBase {
    readonly field: DateFieldInfo;
    min: Date | undefined;
    max: Date | undefined;
    private _maxString;
    constructor(field: DateFieldInfo, parent: NestField | undefined, registry?: FieldRegistry);
    get timeframe(): Malloy.DateTimeframe | undefined;
    registerValue(value: Date): void;
    get minValue(): Date | undefined;
    get maxValue(): Date | undefined;
    get maxString(): string | undefined;
    get minNumber(): number | undefined;
    get maxNumber(): number | undefined;
}
export declare class TimestampField extends FieldBase {
    readonly field: TimestampFieldInfo;
    min: Date | undefined;
    max: Date | undefined;
    private _maxString;
    constructor(field: TimestampFieldInfo, parent: NestField | undefined, registry?: FieldRegistry);
    get timeframe(): Malloy.TimestampTimeframe | undefined;
    registerValue(value: Date): void;
    get minValue(): Date | undefined;
    get maxValue(): Date | undefined;
    get maxString(): string | undefined;
}
export declare class StringField extends FieldBase {
    readonly field: StringFieldInfo;
    min: string | undefined;
    max: string | undefined;
    private _maxString;
    constructor(field: StringFieldInfo, parent: NestField | undefined, registry?: FieldRegistry);
    registerValue(value: string): void;
    get minValue(): string | undefined;
    get maxValue(): string | undefined;
    get maxString(): string | undefined;
}
export declare class SQLNativeField extends FieldBase {
    readonly field: SQLNativeFieldInfo;
    constructor(field: SQLNativeFieldInfo, parent: NestField | undefined, registry?: FieldRegistry);
}
export declare class JSONField extends FieldBase {
    readonly field: JSONFieldInfo;
    constructor(field: JSONFieldInfo, parent: NestField | undefined, registry?: FieldRegistry);
}
export declare class BooleanField extends FieldBase {
    readonly field: BooleanFieldInfo;
    private _maxString;
    constructor(field: BooleanFieldInfo, parent: NestField | undefined, registry?: FieldRegistry);
    get maxString(): string | undefined;
    registerValue(value: boolean): void;
}
export type NestCell = ArrayCell | RecordCell;
export type RecordOrRepeatedRecordCell = RepeatedRecordCell | RecordCell;
export type TimeCell = DateCell | TimestampCell;
export type Cell = ArrayCell | RecordCell | NullCell | NumberCell | DateCell | JSONCell | StringCell | TimestampCell | BooleanCell | SQLNativeCell;
export declare const Cell: {
    from(cell: Malloy.Cell, field: Field, parent: NestCell): Cell;
};
export declare abstract class CellBase {
    readonly cell: Malloy.Cell;
    readonly field: Field;
    readonly parent: NestCell | undefined;
    constructor(cell: Malloy.Cell, field: Field, parent: NestCell | undefined);
    get literalValue(): Malloy.LiteralValue | undefined;
    abstract get value(): CellValue;
    isNull(): this is NullCell;
    isArray(): this is ArrayCell;
    isRecord(): this is RecordCell;
    isRepeatedRecord(): this is RepeatedRecordCell;
    isRecordOrRepeatedRecord(): this is RecordOrRepeatedRecordCell;
    isNest(): this is NestCell;
    isNumber(): this is NumberCell;
    isDate(): this is DateCell;
    isTime(): this is TimeCell;
    isJSON(): this is JSONCell;
    isString(): this is StringCell;
    isTimestamp(): this is TimestampCell;
    isBoolean(): this is BooleanCell;
    asCell(): Cell;
    root(): Cell;
    private getPathInfo;
    getParentRecord(levelsUp: number): RecordCell;
    getRelativeCell(relativeDataPath: string): Cell | undefined;
    cellAt(path: string[] | string): Cell;
    cellAtPath(path: string[]): Cell;
    compareTo(_other: Cell): number;
    canDrill(): boolean;
    getStableDrillQuery(): Malloy.Query | undefined;
    getStableDrillClauses(): Malloy.DrillOperation[] | undefined;
    getDrillValues(): DrillValue[];
    getDrillExpressions(): string[];
    getDrillEntries(): DrillEntry[];
    getStableDrillQueryMalloy(): string | undefined;
    getDrillQueryMalloy(): string;
}
export declare class ArrayCell extends CellBase {
    readonly cell: Malloy.CellWithArrayCell;
    readonly field: ArrayField;
    readonly parent: NestCell | undefined;
    readonly values: Cell[];
    constructor(cell: Malloy.CellWithArrayCell, field: ArrayField, parent: NestCell | undefined);
    get value(): Cell[];
}
export declare class RepeatedRecordCell extends ArrayCell {
    readonly cell: Malloy.CellWithArrayCell;
    readonly field: RepeatedRecordField;
    readonly parent: NestCell | undefined;
    readonly rows: RecordCell[];
    readonly fieldValueSets: Map<string, Set<CellValue>>;
    private plugins;
    private registry?;
    constructor(cell: Malloy.CellWithArrayCell, field: RepeatedRecordField, parent: NestCell | undefined, plugins?: RenderPlugin[], registry?: FieldRegistry);
    get value(): RecordCell[];
}
export declare class RootCell extends RepeatedRecordCell {
    readonly cell: Malloy.CellWithArrayCell;
    readonly field: RootField;
    constructor(cell: Malloy.CellWithArrayCell, field: RootField, plugins?: RenderPlugin[], registry?: FieldRegistry);
}
export type CellValue = string | number | boolean | Date | Cell[] | Record<string, Cell> | null;
export declare class RecordCell extends CellBase {
    readonly cell: Malloy.CellWithRecordCell;
    readonly field: RecordField;
    readonly parent: NestCell | undefined;
    readonly cells: Record<string, Cell>;
    constructor(cell: Malloy.CellWithRecordCell, field: RecordField, parent: NestCell | undefined);
    get rows(): RecordCell[];
    get value(): Record<string, Cell>;
    column(name: string): Cell;
    get columns(): Cell[];
    allCellValues(): Record<string, CellValue>;
    cellAtPath(path: string[]): Cell;
}
export declare class NullCell extends CellBase {
    readonly cell: Malloy.CellWithNullCell;
    readonly field: Field;
    readonly parent: NestCell | undefined;
    constructor(cell: Malloy.CellWithNullCell, field: Field, parent: NestCell | undefined);
    get value(): null;
    get literalValue(): Malloy.LiteralValue | undefined;
}
export declare class NumberCell extends CellBase {
    readonly cell: Malloy.CellWithNumberCell;
    readonly field: NumberField;
    readonly parent: NestCell | undefined;
    constructor(cell: Malloy.CellWithNumberCell, field: NumberField, parent: NestCell | undefined);
    get value(): number;
    compareTo(other: Cell): 1 | 0 | -1;
    get literalValue(): Malloy.LiteralValue | undefined;
}
export declare class DateCell extends CellBase {
    readonly cell: Malloy.CellWithDateCell;
    readonly field: DateField;
    readonly parent: NestCell | undefined;
    constructor(cell: Malloy.CellWithDateCell, field: DateField, parent: NestCell | undefined);
    get value(): Date;
    get timeframe(): Malloy.DateTimeframe | undefined;
    compareTo(other: Cell): 1 | 0 | -1;
    get literalValue(): Malloy.LiteralValue | undefined;
}
export declare class TimestampCell extends CellBase {
    readonly cell: Malloy.CellWithTimestampCell;
    readonly field: TimestampField;
    readonly parent: NestCell | undefined;
    constructor(cell: Malloy.CellWithTimestampCell, field: TimestampField, parent: NestCell | undefined);
    get value(): Date;
    get timeframe(): Malloy.TimestampTimeframe | undefined;
    compareTo(other: Cell): 1 | 0 | -1;
    get literalValue(): Malloy.LiteralValue | undefined;
}
export declare class JSONCell extends CellBase {
    readonly cell: Malloy.CellWithJSONCell;
    readonly field: JSONField;
    readonly parent: NestCell | undefined;
    constructor(cell: Malloy.CellWithJSONCell, field: JSONField, parent: NestCell | undefined);
    get value(): any;
    compareTo(other: Cell): 1 | 0 | -1;
}
export declare class SQLNativeCell extends CellBase {
    readonly cell: Malloy.CellWithSQLNativeCell;
    readonly field: SQLNativeField;
    readonly parent: NestCell | undefined;
    constructor(cell: Malloy.CellWithSQLNativeCell, field: SQLNativeField, parent: NestCell | undefined);
    get value(): any;
    compareTo(other: Cell): 1 | 0 | -1;
}
export declare class StringCell extends CellBase {
    readonly cell: Malloy.CellWithStringCell;
    readonly field: StringField;
    readonly parent: NestCell | undefined;
    constructor(cell: Malloy.CellWithStringCell, field: StringField, parent: NestCell | undefined);
    get value(): string;
    compareTo(other: Cell): number;
    get literalValue(): Malloy.LiteralValue | undefined;
}
export declare class BooleanCell extends CellBase {
    readonly cell: Malloy.CellWithBooleanCell;
    readonly field: BooleanField;
    readonly parent: NestCell | undefined;
    constructor(cell: Malloy.CellWithBooleanCell, field: BooleanField, parent: NestCell | undefined);
    get value(): boolean;
    compareTo(other: Cell): 1 | 0 | -1;
    get literalValue(): Malloy.LiteralValue | undefined;
}
export declare enum FieldType {
    Array = "array",
    RepeatedRecord = "repeated_record",
    Record = "record",
    Number = "number",
    Date = "date",
    JSON = "json",
    String = "string",
    Timestamp = "timestamp",
    Boolean = "boolean",
    SQLNative = "sql_native"
}
export type RenderPluginInstance = {
    name: string;
    processData(field: NestField, cell: NestCell): void;
};
export type RenderPlugin<T extends RenderPluginInstance = {} & RenderPluginInstance> = {
    name: string;
    matches: (fieldTag: Tag, fieldType: FieldType) => boolean;
    plugin: RenderPluginFactory<T>;
};
export type RenderPluginFactory<T extends RenderPluginInstance> = (field: Field) => T;
export declare function getFieldType(field: Field): FieldType;
export {};
