import { SupportedDbtAdapter } from '../types/dbt';
import { CustomDimensionType, DimensionType, FieldType, MetricType, } from '../types/field';
import { FilterOperator } from '../types/filter';
import { DEFAULT_SPOTLIGHT_CONFIG } from '../types/lightdashProjectConfig';
import { TimeFrames } from '../types/timeFrames';
import { defaultNullSafeEqualSql } from '../utils/warehouse';
export const warehouseClientMock = {
    credentials: {},
    getCatalog: async () => ({
        default: {
            public: {
                table: {
                    id: DimensionType.NUMBER,
                },
            },
        },
    }),
    streamQuery: async (_query, streamCallback) => {
        await streamCallback({
            fields: {},
            rows: [],
        });
    },
    executeAsyncQuery: async () => ({
        queryId: null,
        queryMetadata: null,
        totalRows: 0,
        durationMs: 0,
        phaseTimings: {},
    }),
    runQuery: () => Promise.resolve({
        fields: {},
        rows: [],
    }),
    test: () => Promise.resolve(),
    getStartOfWeek: () => undefined,
    getFieldQuoteChar: () => '"',
    getStringQuoteChar: () => "'",
    getEscapeStringQuoteChar: () => "'",
    getFloatingType: () => 'FLOAT',
    getNullSafeEqualSql: defaultNullSafeEqualSql,
    getNullSafeEqualJoinSql: defaultNullSafeEqualSql,
    getAdapterType: () => SupportedDbtAdapter.POSTGRES,
    supportsCteMaterialization: () => true,
    getMetricSql: (sql, metric) => {
        switch (metric.type) {
            case MetricType.AVERAGE:
                return `AVG(${sql})`;
            case MetricType.MAX:
                return `MAX(${sql})`;
            case MetricType.SUM:
                return `SUM(${sql})`;
            default:
                return sql;
        }
    },
    concatString: (...args) => `CONCAT(${args.join(', ')})`,
    getAllTables() {
        throw new Error('Function not implemented.');
    },
    getFields() {
        throw new Error('Function not implemented.');
    },
    parseWarehouseCatalog() {
        throw new Error('Function not implemented.');
    },
    parseError() {
        throw new Error('Function not implemented.');
    },
    escapeString: (value) => value,
    castToTimestamp: (date) => `CAST('${date.toISOString()}' AS TIMESTAMP)`,
    getIntervalSql: (value, unit) => `INTERVAL '${value} ${unit}'`,
    getTimestampDiffSeconds: (startTimestampSql, endTimestampSql) => `EXTRACT(EPOCH FROM (${endTimestampSql} - ${startTimestampSql}))`,
    getMedianSql: (valueSql) => `PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY ${valueSql})`,
    buildArray: (elements) => `ARRAY[${elements.join(', ')}]`,
    buildArrayAgg: (expression, orderBy) => orderBy
        ? `ARRAY_AGG(${expression} ORDER BY ${orderBy})`
        : `ARRAY_AGG(${expression})`,
};
const sourceMock = {
    path: '',
    content: '',
    range: {
        start: {
            line: 0,
            character: 0,
        },
        end: {
            line: 0,
            character: 0,
        },
    },
};
export const exploreBase = {
    targetDatabase: SupportedDbtAdapter.POSTGRES,
    name: '',
    label: '',
    tags: [],
    spotlight: {
        visibility: 'show',
        categories: [],
    },
    baseTable: 'a',
    joinedTables: [],
    tables: {},
    groupLabel: undefined,
    warehouse: undefined,
    sqlPath: undefined,
    ymlPath: undefined,
    databricksCompute: undefined,
};
export const exploreOneEmptyTable = {
    ...exploreBase,
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            dimensions: {},
            metrics: {},
            lineageGraph: {},
            source: sourceMock,
            groupLabel: undefined,
        },
    },
};
export const exploreOneEmptyTableCompiled = {
    ...exploreBase,
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {},
            metrics: {},
            lineageGraph: {},
            source: sourceMock,
            groupLabel: undefined,
        },
    },
};
export const createExploreWithRequiredFilters = (requiredFilters) => ({
    ...exploreOneEmptyTable,
    name: 'orders',
    label: 'Orders',
    baseTable: 'orders',
    tables: {
        orders: {
            ...exploreOneEmptyTable.tables.a,
            name: 'orders',
            label: 'Orders',
            dimensions: {
                credit_card_amount: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'credit_card_amount',
                    label: 'Credit card amount',
                    table: 'orders',
                    tableLabel: 'Orders',
                    sql: '${TABLE}.credit_card_amount',
                    hidden: true,
                },
                has_credit_card_payment: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.BOOLEAN,
                    name: 'has_credit_card_payment',
                    label: 'Has credit card payment',
                    table: 'orders',
                    tableLabel: 'Orders',
                    sql: '${TABLE}.credit_card_amount > 0',
                    hidden: false,
                    isAdditionalDimension: true,
                },
            },
            requiredFilters,
        },
    },
});
export const exploreMissingBaseTable = {
    ...exploreBase,
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
};
export const exploreMissingJoinTable = {
    ...exploreBase,
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
    joinedTables: [
        {
            table: 'b',
            sqlOn: '',
        },
    ],
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            dimensions: {},
            metrics: {},
            lineageGraph: {},
            source: sourceMock,
            groupLabel: undefined,
        },
    },
};
export const exploreCircularDimensionReference = {
    ...exploreBase,
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${a.dim1}', // circular reference
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const exploreCircularDimensionShortReference = {
    ...exploreCircularDimensionReference,
    tables: {
        a: {
            ...exploreCircularDimensionReference.tables.a,
            dimensions: {
                dim1: {
                    ...exploreCircularDimensionReference.tables.a.dimensions
                        .dim1,
                    sql: '${dim1}', // circular short reference
                },
            },
        },
    },
};
export const exploreCircularMetricReference = {
    ...exploreBase,
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim1',
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {
                met1: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.STRING,
                    name: 'met1',
                    label: 'met1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${a.met1}', // circular reference
                    source: sourceMock,
                    hidden: false,
                },
            },
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const exploreCircularMetricShortReference = {
    ...exploreCircularDimensionReference,
    tables: {
        a: {
            ...exploreCircularDimensionReference.tables.a,
            metrics: {
                met1: {
                    ...exploreCircularDimensionReference.tables.a.metrics.met1,
                    sql: '${met1}', // circular short reference
                },
            },
        },
    },
};
export const exploreTableSelfReference = {
    ...exploreBase,
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim1',
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const exploreTableSelfReferenceSqlWhere = {
    ...exploreBase,
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim1',
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const exploreTableSelfReferenceCompiled = {
    ...exploreBase,
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim1',
                    compiledSql: '"a".dim1',
                    tablesReferences: ['a'],
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const exploreTableSelfReferenceCompiledSqlWhere = {
    ...exploreBase,
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim1',
                    compiledSql: '"a".dim1',
                    tablesReferences: ['a'],
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const exploreReferenceDimension = {
    ...exploreBase,
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim1',
                    source: sourceMock,
                    hidden: false,
                },
                dim2: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim2',
                    label: 'dim2',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${a.dim1}',
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const exploreReferenceDimensionCompiled = {
    ...exploreBase,
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim1',
                    compiledSql: '"a".dim1',
                    tablesReferences: ['a'],
                    source: sourceMock,
                    hidden: false,
                },
                dim2: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim2',
                    label: 'dim2',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${a.dim1}',
                    compiledSql: '("a".dim1)',
                    tablesReferences: ['a'],
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const exploreComplexReference = {
    ...exploreBase,
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim1',
                    source: sourceMock,
                    hidden: false,
                },
                dim2: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'dim2',
                    label: 'dim2',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${a.dim1}',
                    source: sourceMock,
                    hidden: false,
                },
                dim3: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'dim3',
                    label: 'dim3',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim3 + ${a.dim2} + ${dim1}',
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {
                m1: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.AVERAGE,
                    name: 'm1',
                    label: 'm1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${dim3}',
                    source: sourceMock,
                    hidden: false,
                },
            },
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const exploreComplexReferenceCompiled = {
    ...exploreBase,
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim1',
                    compiledSql: '"a".dim1',
                    tablesReferences: ['a'],
                    source: sourceMock,
                    hidden: false,
                },
                dim2: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'dim2',
                    label: 'dim2',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${a.dim1}',
                    compiledSql: '("a".dim1)',
                    tablesReferences: ['a'],
                    source: sourceMock,
                    hidden: false,
                },
                dim3: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'dim3',
                    label: 'dim3',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim3 + ${a.dim2} + ${dim1}',
                    compiledSql: '"a".dim3 + (("a".dim1)) + ("a".dim1)',
                    tablesReferences: ['a'],
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {
                m1: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.AVERAGE,
                    name: 'm1',
                    label: 'm1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${dim3}',
                    compiledSql: 'AVG(("a".dim3 + (("a".dim1)) + ("a".dim1)))',
                    compiledValueSql: '("a".dim3 + (("a".dim1)) + ("a".dim1))',
                    tablesReferences: ['a'],
                    source: sourceMock,
                    hidden: false,
                    showUnderlyingValues: undefined,
                },
            },
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const simpleJoinedExplore = {
    ...exploreBase,
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
    joinedTables: [
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${b.dim1}',
        },
    ],
    tables: {
        a: {
            name: 'a',
            label: 'Custom A label',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'Custom A label',
                    sql: '${TABLE}.dim1',
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
        b: {
            name: 'b',
            label: 'Custom B label',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.tableb',
            sqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'b',
                    tableLabel: 'Custom B label',
                    sql: '${TABLE}.dim1',
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const compiledSimpleJoinedExplore = {
    ...exploreBase,
    joinedTables: [
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${b.dim1}',
            compiledSqlOn: '("a".dim1) = ("b".dim1)',
            tablesReferences: ['a', 'b'],
            relationship: undefined,
            type: undefined,
            hidden: undefined,
            always: undefined,
        },
    ],
    tables: {
        a: {
            name: 'a',
            label: 'Custom A label',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'Custom A label',
                    sql: '${TABLE}.dim1',
                    compiledSql: '"a".dim1',
                    tablesReferences: ['a'],
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
        b: {
            name: 'b',
            originalName: 'b',
            label: 'Custom B label',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.tableb',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'b',
                    tableLabel: 'Custom B label',
                    sql: '${TABLE}.dim1',
                    compiledSql: '"b".dim1',
                    tablesReferences: ['b'],
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
            hidden: undefined,
        },
    },
};
export const exploreWithJoinWithFieldsAndGroups = {
    ...simpleJoinedExplore,
    joinedTables: [
        {
            ...simpleJoinedExplore.joinedTables[0],
            fields: ['dim2'],
        },
    ],
    tables: {
        ...simpleJoinedExplore.tables,
        b: {
            ...simpleJoinedExplore.tables.b,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'b',
                    tableLabel: 'Custom B label',
                    sql: '${TABLE}.dim1',
                    source: sourceMock,
                    hidden: false,
                },
                dim2: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.DATE,
                    name: 'dim2',
                    label: 'dim2',
                    table: 'b',
                    tableLabel: 'Custom B label',
                    sql: '${TABLE}.dim2',
                    source: sourceMock,
                    hidden: false,
                    timeInterval: TimeFrames.DAY,
                    groups: ['test'],
                },
                dim2_DAY: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.DATE,
                    name: 'dim2_DAY',
                    label: 'dim2_DAY',
                    table: 'b',
                    tableLabel: 'Custom B label',
                    sql: '${TABLE}.dim2',
                    source: sourceMock,
                    hidden: false,
                    timeInterval: TimeFrames.DAY,
                    timeIntervalBaseDimensionName: 'dim2',
                    groups: ['test', 'dim2'],
                },
            },
        },
    },
};
export const compiledExploreWithJoinWithFieldsAndGroups = {
    ...exploreBase,
    joinedTables: [
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${b.dim1}',
            compiledSqlOn: '("a".dim1) = ("b".dim1)',
            tablesReferences: ['a', 'b'],
            type: undefined,
            hidden: undefined,
            always: undefined,
            relationship: undefined,
        },
    ],
    tables: {
        a: {
            name: 'a',
            label: 'Custom A label',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'Custom A label',
                    sql: '${TABLE}.dim1',
                    compiledSql: '"a".dim1',
                    tablesReferences: ['a'],
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
        b: {
            name: 'b',
            originalName: 'b',
            label: 'Custom B label',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.tableb',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'b',
                    tableLabel: 'Custom B label',
                    sql: '${TABLE}.dim1',
                    compiledSql: '"b".dim1',
                    tablesReferences: ['b'],
                    source: sourceMock,
                    hidden: true,
                },
                dim2: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.DATE,
                    name: 'dim2',
                    label: 'dim2',
                    table: 'b',
                    tableLabel: 'Custom B label',
                    sql: '${TABLE}.dim2',
                    compiledSql: '"b".dim2',
                    tablesReferences: ['b'],
                    source: sourceMock,
                    hidden: false,
                    timeInterval: TimeFrames.DAY,
                    groups: ['test'],
                },
                dim2_DAY: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.DATE,
                    name: 'dim2_DAY',
                    label: 'dim2_DAY',
                    table: 'b',
                    tableLabel: 'Custom B label',
                    sql: '${TABLE}.dim2',
                    compiledSql: '"b".dim2',
                    tablesReferences: ['b'],
                    source: sourceMock,
                    hidden: false,
                    timeInterval: TimeFrames.DAY,
                    timeIntervalBaseDimensionName: 'dim2',
                    groups: ['test', 'dim2'],
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
            hidden: undefined,
        },
    },
};
export const exploreReferenceInJoin = {
    ...simpleJoinedExplore,
    tables: {
        ...simpleJoinedExplore.tables,
        b: {
            ...simpleJoinedExplore.tables.b,
            dimensions: {
                ...simpleJoinedExplore.tables.b.dimensions,
                dim2: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim2',
                    label: 'dim2',
                    table: 'b',
                    tableLabel: 'Custom B label',
                    sql: '${a.dim1}',
                    source: sourceMock,
                    hidden: false,
                },
                dim3: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim3',
                    label: 'dim3',
                    table: 'b',
                    tableLabel: 'Custom B label',
                    sql: '${TABLE}.dim3',
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const exploreReferenceInJoinCompiled = {
    ...compiledSimpleJoinedExplore,
    tables: {
        ...compiledSimpleJoinedExplore.tables,
        b: {
            ...compiledSimpleJoinedExplore.tables.b,
            dimensions: {
                ...compiledSimpleJoinedExplore.tables.b.dimensions,
                dim2: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim2',
                    label: 'dim2',
                    table: 'b',
                    tableLabel: 'Custom B label',
                    sql: '${a.dim1}',
                    compiledSql: '("a".dim1)',
                    tablesReferences: ['b', 'a'],
                    source: sourceMock,
                    hidden: false,
                },
                dim3: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'dim3',
                    label: 'dim3',
                    table: 'b',
                    tableLabel: 'Custom B label',
                    sql: '${TABLE}.dim3',
                    compiledSql: '"b".dim3',
                    tablesReferences: ['b'],
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {},
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const joinedExploreOverridingJoinLabel = {
    ...simpleJoinedExplore,
    joinedTables: [
        {
            ...simpleJoinedExplore.joinedTables[0],
            label: 'Custom join label',
        },
    ],
};
export const compiledJoinedExploreOverridingJoinLabel = {
    ...compiledSimpleJoinedExplore,
    tables: {
        ...compiledSimpleJoinedExplore.tables,
        b: {
            ...compiledSimpleJoinedExplore.tables.b,
            label: 'Custom join label',
            dimensions: {
                ...compiledSimpleJoinedExplore.tables.b.dimensions,
                dim1: {
                    ...compiledSimpleJoinedExplore.tables.b.dimensions.dim1,
                    tableLabel: 'Custom join label',
                },
            },
        },
    },
};
export const joinedExploreOverridingJoinAlias = {
    ...simpleJoinedExplore,
    joinedTables: [
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${custom_alias.dim1}',
            alias: 'custom_alias',
        },
    ],
};
export const compiledJoinedExploreOverridingJoinAlias = {
    ...compiledSimpleJoinedExplore,
    joinedTables: [
        {
            table: 'custom_alias',
            sqlOn: '${a.dim1} = ${custom_alias.dim1}',
            compiledSqlOn: '("a".dim1) = ("custom_alias".dim1)',
            tablesReferences: ['a', 'custom_alias'],
            type: undefined,
            hidden: undefined,
            always: undefined,
            relationship: undefined,
        },
    ],
    tables: {
        a: compiledSimpleJoinedExplore.tables.a,
        custom_alias: {
            ...compiledSimpleJoinedExplore.tables.b,
            name: 'custom_alias',
            label: 'Custom alias',
            dimensions: {
                ...compiledSimpleJoinedExplore.tables.b.dimensions,
                dim1: {
                    ...compiledSimpleJoinedExplore.tables.b.dimensions.dim1,
                    table: 'custom_alias',
                    tableLabel: 'Custom alias',
                    compiledSql: '"custom_alias".dim1',
                    tablesReferences: ['custom_alias'],
                },
            },
        },
    },
};
export const joinedExploreOverridingAliasAndLabel = {
    ...simpleJoinedExplore,
    joinedTables: [
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${custom_alias.dim1}',
            label: 'Custom join label',
            alias: 'custom_alias',
        },
    ],
};
export const compiledJoinedExploreOverridingAliasAndLabel = {
    ...compiledSimpleJoinedExplore,
    joinedTables: [
        {
            table: 'custom_alias',
            sqlOn: '${a.dim1} = ${custom_alias.dim1}',
            compiledSqlOn: '("a".dim1) = ("custom_alias".dim1)',
            tablesReferences: ['a', 'custom_alias'],
            type: undefined,
            hidden: undefined,
            always: undefined,
            relationship: undefined,
        },
    ],
    tables: {
        a: compiledSimpleJoinedExplore.tables.a,
        custom_alias: {
            ...compiledSimpleJoinedExplore.tables.b,
            name: 'custom_alias',
            label: 'Custom join label',
            dimensions: {
                ...compiledSimpleJoinedExplore.tables.b.dimensions,
                dim1: {
                    ...compiledSimpleJoinedExplore.tables.b.dimensions.dim1,
                    table: 'custom_alias',
                    tableLabel: 'Custom join label',
                    compiledSql: '"custom_alias".dim1',
                    tablesReferences: ['custom_alias'],
                },
            },
        },
    },
};
export const joinedExploreWithTwoJoinsToTheSameTable = {
    ...simpleJoinedExplore,
    joinedTables: [
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${b.dim1}',
        },
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${custom_alias.dim1}',
            label: 'Custom join label',
            alias: 'custom_alias',
        },
    ],
    tables: {
        ...simpleJoinedExplore.tables,
        a: {
            ...simpleJoinedExplore.tables.a,
            metrics: {
                m1: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.SUM,
                    name: 'm1',
                    label: 'm1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${custom_alias.dim1}',
                    source: sourceMock,
                    hidden: false,
                },
            },
        },
    },
};
export const compiledJoinedExploreWithTwoJoinsToTheSameTable = {
    ...compiledSimpleJoinedExplore,
    joinedTables: [
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${b.dim1}',
            compiledSqlOn: '("a".dim1) = ("b".dim1)',
            tablesReferences: ['a', 'b'],
            type: undefined,
            hidden: undefined,
            always: undefined,
            relationship: undefined,
        },
        {
            table: 'custom_alias',
            sqlOn: '${a.dim1} = ${custom_alias.dim1}',
            compiledSqlOn: '("a".dim1) = ("custom_alias".dim1)',
            tablesReferences: ['a', 'custom_alias'],
            type: undefined,
            hidden: undefined,
            always: undefined,
            relationship: undefined,
        },
    ],
    tables: {
        a: {
            ...compiledSimpleJoinedExplore.tables.a,
            metrics: {
                m1: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.SUM,
                    name: 'm1',
                    label: 'm1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${custom_alias.dim1}',
                    compiledSql: 'SUM(("custom_alias".dim1))',
                    compiledValueSql: '("custom_alias".dim1)',
                    tablesReferences: ['a', 'custom_alias'],
                    source: sourceMock,
                    hidden: false,
                    showUnderlyingValues: undefined,
                },
            },
        },
        b: compiledSimpleJoinedExplore.tables.b,
        custom_alias: {
            ...compiledSimpleJoinedExplore.tables.b,
            name: 'custom_alias',
            label: 'Custom join label',
            dimensions: {
                ...compiledSimpleJoinedExplore.tables.b.dimensions,
                dim1: {
                    ...compiledSimpleJoinedExplore.tables.b.dimensions.dim1,
                    table: 'custom_alias',
                    tableLabel: 'Custom join label',
                    compiledSql: '"custom_alias".dim1',
                    tablesReferences: ['custom_alias'],
                },
            },
        },
    },
};
export const exploreWithHiddenJoin = {
    ...exploreReferenceInJoin,
    joinedTables: [
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${b.dim1}',
            hidden: true,
        },
    ],
};
export const compiledExploreWithHiddenJoin = {
    ...exploreReferenceInJoinCompiled,
    joinedTables: [
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${b.dim1}',
            compiledSqlOn: '("a".dim1) = ("b".dim1)',
            tablesReferences: ['a', 'b'],
            type: undefined,
            hidden: true,
            always: undefined,
            relationship: undefined,
        },
    ],
    tables: {
        ...exploreReferenceInJoinCompiled.tables,
        b: {
            ...exploreReferenceInJoinCompiled.tables.b,
            dimensions: Object.entries(exploreReferenceInJoinCompiled.tables.b.dimensions).reduce((acc, [key, value]) => ({
                ...acc,
                [key]: {
                    ...value,
                    hidden: true,
                },
            }), {}),
            hidden: true,
        },
    },
};
export const joinedExploreWithSubsetOfFields = {
    ...exploreReferenceInJoin,
    joinedTables: [
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${b.dim1}',
            fields: ['dim1'],
        },
    ],
};
export const compiledJoinedExploreWithSubsetOfFields = {
    ...exploreReferenceInJoinCompiled,
    tables: {
        ...exploreReferenceInJoinCompiled.tables,
        b: {
            ...exploreReferenceInJoinCompiled.tables.b,
            dimensions: {
                dim1: {
                    ...exploreReferenceInJoinCompiled.tables.b.dimensions.dim1,
                },
            },
        },
    },
};
export const joinedExploreWithSubsetOfFieldsThatDontIncludeSqlFields = {
    ...exploreReferenceInJoin,
    joinedTables: [
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${b.dim1}',
            fields: ['dim2'], // doesn't include "dim1" that is required for join SQL
        },
    ],
};
export const compiledJoinedExploreWithSubsetOfFieldsThatDontIncludeSqlFields = {
    ...exploreReferenceInJoinCompiled,
    tables: {
        ...exploreReferenceInJoinCompiled.tables,
        b: {
            ...exploreReferenceInJoinCompiled.tables.b,
            dimensions: {
                dim1: {
                    ...exploreReferenceInJoinCompiled.tables.b.dimensions
                        .dim1,
                    hidden: true,
                },
                dim2: {
                    ...exploreReferenceInJoinCompiled.tables.b.dimensions
                        .dim2,
                },
            },
        },
    },
};
export const joinedExploreWithJoinAliasAndSubsetOfFieldsThatDontIncludeSqlFields = {
    ...exploreReferenceInJoin,
    joinedTables: [
        {
            table: 'b',
            alias: 'custom_alias', // includes alias
            sqlOn: '${a.dim1} = ${custom_alias.dim1}',
            fields: ['dim2', 'dim3'], // doesn't include "dim1" that is required for join SQL
        },
    ],
};
export const compiledJoinedExploreWithJoinAliasAndSubsetOfFieldsThatDontIncludeSqlFields = {
    ...exploreReferenceInJoinCompiled,
    joinedTables: [
        {
            table: 'custom_alias',
            sqlOn: '${a.dim1} = ${custom_alias.dim1}',
            compiledSqlOn: '("a".dim1) = ("custom_alias".dim1)',
            tablesReferences: ['a', 'custom_alias'],
            type: undefined,
            hidden: undefined,
            always: undefined,
            relationship: undefined,
        },
    ],
    tables: {
        a: exploreReferenceInJoinCompiled.tables.a,
        custom_alias: {
            ...exploreReferenceInJoinCompiled.tables.b,
            name: 'custom_alias',
            label: 'Custom alias',
            dimensions: {
                ...exploreReferenceInJoinCompiled.tables.b.dimensions,
                dim1: {
                    ...exploreReferenceInJoinCompiled.tables.b.dimensions
                        .dim1,
                    table: 'custom_alias',
                    tableLabel: 'Custom alias',
                    compiledSql: '"custom_alias".dim1',
                    tablesReferences: ['custom_alias'],
                    hidden: true,
                },
                dim2: {
                    ...exploreReferenceInJoinCompiled.tables.b.dimensions
                        .dim2,
                    table: 'custom_alias',
                    tableLabel: 'Custom alias',
                    compiledSql: '("a".dim1)',
                    tablesReferences: ['custom_alias', 'a'],
                },
                dim3: {
                    ...exploreReferenceInJoinCompiled.tables.b.dimensions
                        .dim3,
                    table: 'custom_alias',
                    tableLabel: 'Custom alias',
                    compiledSql: '"custom_alias".dim3',
                    tablesReferences: ['custom_alias'],
                },
            },
        },
    },
};
export const exploreWithMetricNumber = {
    ...exploreBase,
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim1',
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {
                m1: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.SUM,
                    name: 'm1',
                    label: 'm1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${dim1}',
                    source: sourceMock,
                    hidden: false,
                    spotlight: {
                        visibility: 'hide',
                    },
                },
                m2: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.NUMBER,
                    name: 'm2',
                    label: 'm2',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '2 + ${m1}',
                    source: sourceMock,
                    hidden: false,
                },
            },
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const exploreWithMetricNumberCompiled = {
    name: exploreWithMetricNumber.name,
    label: exploreWithMetricNumber.label,
    baseTable: exploreWithMetricNumber.baseTable,
    tags: exploreWithMetricNumber.tags,
    targetDatabase: exploreWithMetricNumber.targetDatabase,
    warehouse: exploreWithMetricNumber.warehouse,
    ymlPath: exploreWithMetricNumber.ymlPath,
    sqlPath: exploreWithMetricNumber.sqlPath,
    groupLabel: exploreWithMetricNumber.groupLabel,
    databricksCompute: exploreWithMetricNumber.databricksCompute,
    spotlight: {
        visibility: 'show',
        categories: [],
    },
    joinedTables: [],
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                dim1: {
                    ...exploreWithMetricNumber.tables.a.dimensions.dim1,
                    compiledSql: '"a".dim1',
                    tablesReferences: ['a'],
                },
            },
            metrics: {
                m1: {
                    ...exploreWithMetricNumber.tables.a.metrics.m1,
                    compiledSql: 'SUM(("a".dim1))',
                    compiledValueSql: '("a".dim1)',
                    tablesReferences: ['a'],
                    showUnderlyingValues: undefined,
                },
                m2: {
                    ...exploreWithMetricNumber.tables.a.metrics.m2,
                    compiledSql: '2 + (SUM(("a".dim1)))',
                    compiledValueSql: '2 + (SUM(("a".dim1)))',
                    tablesReferences: ['a'],
                    showUnderlyingValues: undefined,
                },
            },
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
/**
 * Test case for non-aggregate metric (type: NUMBER) that has an aggregation
 * function in its SQL and references a dimension. This pattern is common in
 * Looker where type:number measures have sql like "count(distinct ${user_id})".
 */
export const exploreWithNonAggregateMetricWithAggregationInSql = {
    ...exploreBase,
    baseTable: 'events',
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
    tables: {
        events: {
            name: 'events',
            label: 'events',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.events',
            sqlWhere: undefined,
            dimensions: {
                user_id: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'user_id',
                    label: 'user_id',
                    table: 'events',
                    tableLabel: 'events',
                    sql: '${TABLE}.user_id',
                    source: sourceMock,
                    hidden: false,
                },
                amount: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'amount',
                    label: 'amount',
                    table: 'events',
                    tableLabel: 'events',
                    sql: '${TABLE}.amount',
                    source: sourceMock,
                    hidden: false,
                },
                status: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'status',
                    label: 'status',
                    table: 'events',
                    tableLabel: 'events',
                    sql: '${TABLE}.status',
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {
                // Non-aggregate (NUMBER) with count(distinct) - should allow dimension ref
                user_count: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.NUMBER,
                    name: 'user_count',
                    label: 'user_count',
                    table: 'events',
                    tableLabel: 'events',
                    sql: 'count(distinct ${user_id})',
                    source: sourceMock,
                    hidden: false,
                },
                // Non-aggregate (NUMBER) with stddev - should allow dimension ref
                amount_stddev: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.NUMBER,
                    name: 'amount_stddev',
                    label: 'amount_stddev',
                    table: 'events',
                    tableLabel: 'events',
                    sql: 'stddev(${amount})',
                    source: sourceMock,
                    hidden: false,
                },
                // Non-aggregate (NUMBER) with CASE containing aggregation
                conditional_count: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.NUMBER,
                    name: 'conditional_count',
                    label: 'conditional_count',
                    table: 'events',
                    tableLabel: 'events',
                    sql: "CASE WHEN ${status} = 'active' THEN count(distinct ${user_id}) ELSE 0 END",
                    source: sourceMock,
                    hidden: false,
                },
                // Non-aggregate (NUMBER) with COALESCE-wrapped aggregation
                safe_avg: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.NUMBER,
                    name: 'safe_avg',
                    label: 'safe_avg',
                    table: 'events',
                    tableLabel: 'events',
                    sql: 'COALESCE(avg(${amount}), 0)',
                    source: sourceMock,
                    hidden: false,
                },
            },
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const exploreWithNonAggregateMetricWithAggregationInSqlCompiled = {
    name: exploreWithNonAggregateMetricWithAggregationInSql.name,
    label: exploreWithNonAggregateMetricWithAggregationInSql.label,
    baseTable: exploreWithNonAggregateMetricWithAggregationInSql.baseTable,
    tags: exploreWithNonAggregateMetricWithAggregationInSql.tags,
    targetDatabase: exploreWithNonAggregateMetricWithAggregationInSql.targetDatabase,
    warehouse: exploreWithNonAggregateMetricWithAggregationInSql.warehouse,
    ymlPath: exploreWithNonAggregateMetricWithAggregationInSql.ymlPath,
    sqlPath: exploreWithNonAggregateMetricWithAggregationInSql.sqlPath,
    groupLabel: exploreWithNonAggregateMetricWithAggregationInSql.groupLabel,
    databricksCompute: exploreWithNonAggregateMetricWithAggregationInSql.databricksCompute,
    spotlight: {
        visibility: 'show',
        categories: [],
    },
    joinedTables: [],
    tables: {
        events: {
            name: 'events',
            label: 'events',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.events',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                user_id: {
                    ...exploreWithNonAggregateMetricWithAggregationInSql
                        .tables.events.dimensions.user_id,
                    compiledSql: '"events".user_id',
                    tablesReferences: ['events'],
                },
                amount: {
                    ...exploreWithNonAggregateMetricWithAggregationInSql
                        .tables.events.dimensions.amount,
                    compiledSql: '"events".amount',
                    tablesReferences: ['events'],
                },
                status: {
                    ...exploreWithNonAggregateMetricWithAggregationInSql
                        .tables.events.dimensions.status,
                    compiledSql: '"events".status',
                    tablesReferences: ['events'],
                },
            },
            metrics: {
                user_count: {
                    ...exploreWithNonAggregateMetricWithAggregationInSql
                        .tables.events.metrics.user_count,
                    compiledSql: 'count(distinct ("events".user_id))',
                    compiledValueSql: 'count(distinct ("events".user_id))',
                    tablesReferences: ['events'],
                    showUnderlyingValues: undefined,
                },
                amount_stddev: {
                    ...exploreWithNonAggregateMetricWithAggregationInSql
                        .tables.events.metrics.amount_stddev,
                    compiledSql: 'stddev(("events".amount))',
                    compiledValueSql: 'stddev(("events".amount))',
                    tablesReferences: ['events'],
                    showUnderlyingValues: undefined,
                },
                conditional_count: {
                    ...exploreWithNonAggregateMetricWithAggregationInSql
                        .tables.events.metrics.conditional_count,
                    compiledSql: `CASE WHEN ("events".status) = 'active' THEN count(distinct ("events".user_id)) ELSE 0 END`,
                    compiledValueSql: `CASE WHEN ("events".status) = 'active' THEN count(distinct ("events".user_id)) ELSE 0 END`,
                    tablesReferences: ['events'],
                    showUnderlyingValues: undefined,
                },
                safe_avg: {
                    ...exploreWithNonAggregateMetricWithAggregationInSql
                        .tables.events.metrics.safe_avg,
                    compiledSql: 'COALESCE(avg(("events".amount)), 0)',
                    compiledValueSql: 'COALESCE(avg(("events".amount)), 0)',
                    tablesReferences: ['events'],
                    showUnderlyingValues: undefined,
                },
            },
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const tablesWithMetricsWithFilters = {
    table1: {
        name: 'table1',
        label: 'table1',
        database: 'database',
        schema: 'schema',
        sqlTable: '"db"."schema"."table1"',
        sqlWhere: undefined,
        dimensions: {
            dim1: {
                type: DimensionType.NUMBER,
                name: 'dim1',
                label: 'dim1',
                table: 'table1',
                tableLabel: 'table1',
                fieldType: FieldType.DIMENSION,
                sql: '${TABLE}.dim1',
                hidden: false,
            },
            shared: {
                type: DimensionType.STRING,
                name: 'shared',
                label: 'shared',
                table: 'table1',
                tableLabel: 'table1',
                fieldType: FieldType.DIMENSION,
                sql: '${TABLE}.shared',
                hidden: false,
            },
            with_reference: {
                type: DimensionType.NUMBER,
                name: 'with_reference',
                label: 'with_reference',
                table: 'table1',
                tableLabel: 'table1',
                fieldType: FieldType.DIMENSION,
                sql: '${TABLE}.dim1 + ${table2.dim2}',
                hidden: false,
            },
        },
        metrics: {
            metric1: {
                type: MetricType.MAX,
                fieldType: FieldType.METRIC,
                table: 'table1',
                tableLabel: 'table1',
                name: 'metric1',
                label: 'metric1',
                sql: '${TABLE}.number_column',
                hidden: false,
                filters: [
                    {
                        id: 'filter1',
                        target: { fieldRef: 'shared' },
                        operator: FilterOperator.INCLUDE,
                        values: ['foo'],
                    },
                ],
            },
            metric_with_sql: {
                type: MetricType.MAX,
                fieldType: FieldType.METRIC,
                table: 'table1',
                tableLabel: 'table1',
                name: 'metric_with_sql',
                label: 'metric_with_sql',
                sql: 'CASE WHEN ${TABLE}.number_column THEN 1 ELSE 0 END',
                hidden: false,
                filters: [
                    {
                        id: 'filter1',
                        target: { fieldRef: 'shared' },
                        operator: FilterOperator.INCLUDE,
                        values: ['foo'],
                    },
                ],
            },
        },
        lineageGraph: {},
        groupLabel: undefined,
    },
    table2: {
        name: 'table2',
        label: 'table2',
        database: 'database',
        schema: 'schema',
        sqlTable: '"db"."schema"."table2"',
        sqlWhere: undefined,
        dimensions: {
            dim2: {
                type: DimensionType.NUMBER,
                name: 'dim2',
                label: 'dim2',
                table: 'table2',
                tableLabel: 'table2',
                fieldType: FieldType.DIMENSION,
                sql: '${TABLE}.dim2',
                hidden: false,
            },
            shared: {
                type: DimensionType.STRING,
                name: 'shared',
                label: 'shared',
                table: 'table2',
                tableLabel: 'table2',
                fieldType: FieldType.DIMENSION,
                sql: '${TABLE}.shared',
                hidden: false,
            },
        },
        metrics: {
            metric2: {
                type: MetricType.MAX,
                fieldType: FieldType.METRIC,
                table: 'table2',
                tableLabel: 'table2',
                name: 'metric2',
                label: 'metric2',
                sql: '${TABLE}.number_column',
                hidden: false,
                filters: [
                    {
                        id: 'filter2_1',
                        target: { fieldRef: 'dim2' },
                        operator: FilterOperator.LESS_THAN,
                        values: [10],
                    },
                    {
                        id: 'filter2_2',
                        target: { fieldRef: 'dim2' },
                        operator: FilterOperator.GREATER_THAN,
                        values: [5],
                    },
                ],
            },
        },
        lineageGraph: {},
        groupLabel: undefined,
    },
};
export const exploreWithRequiredAttributes = {
    ...exploreBase,
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
    joinedTables: [
        {
            table: 'b',
            sqlOn: '',
        },
    ],
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim1',
                    source: sourceMock,
                    hidden: false,
                    requiredAttributes: {
                        is_admin: 'true',
                    },
                },
            },
            metrics: {
                met1: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.NUMBER,
                    name: 'met1',
                    label: 'met1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: `100 - $\{b.met1}`, // joined table reference
                    source: sourceMock,
                    hidden: false,
                },
            },
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
        b: {
            name: 'b',
            label: 'b',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'b',
                    tableLabel: 'b',
                    sql: '${TABLE}.dim1',
                    source: sourceMock,
                    hidden: false,
                    requiredAttributes: {
                        section: 'marketing',
                    },
                },
            },
            metrics: {
                met1: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.SUM,
                    name: 'met1',
                    label: 'met1',
                    table: 'b',
                    tableLabel: 'b',
                    sql: '${b.dim1}',
                    source: sourceMock,
                    hidden: false,
                },
            },
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
            requiredAttributes: {
                is_admin: 'true',
            },
        },
    },
};
export const exploreWithRequiredAttributesCompiled = {
    ...exploreBase,
    joinedTables: [
        {
            compiledSqlOn: '',
            tablesReferences: [],
            sqlOn: '',
            table: 'b',
            type: undefined,
            hidden: undefined,
            always: undefined,
            relationship: undefined,
        },
    ],
    tables: {
        a: {
            name: 'a',
            label: 'a',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '${TABLE}.dim1',
                    compiledSql: '"a".dim1',
                    tablesReferences: ['a'],
                    source: sourceMock,
                    hidden: false,
                    requiredAttributes: {
                        is_admin: 'true',
                    },
                },
            },
            metrics: {
                met1: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.NUMBER,
                    name: 'met1',
                    label: 'met1',
                    table: 'a',
                    tableLabel: 'a',
                    sql: '100 - ${b.met1}',
                    compiledSql: '100 - (SUM(("b".dim1)))',
                    compiledValueSql: '100 - (SUM(("b".dim1)))',
                    source: sourceMock,
                    hidden: false,
                    tablesReferences: ['a', 'b'],
                    tablesRequiredAttributes: {
                        b: {
                            is_admin: 'true',
                        },
                    },
                    showUnderlyingValues: undefined,
                },
            },
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
        b: {
            name: 'b',
            originalName: 'b',
            label: 'b',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.table',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            hidden: undefined,
            dimensions: {
                dim1: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'dim1',
                    label: 'dim1',
                    table: 'b',
                    tableLabel: 'b',
                    sql: '${TABLE}.dim1',
                    compiledSql: '"b".dim1',
                    source: sourceMock,
                    hidden: false,
                    requiredAttributes: {
                        section: 'marketing',
                    },
                    tablesReferences: ['b'],
                    tablesRequiredAttributes: {
                        b: {
                            is_admin: 'true',
                        },
                    },
                },
            },
            metrics: {
                met1: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.SUM,
                    name: 'met1',
                    label: 'met1',
                    table: 'b',
                    tableLabel: 'b',
                    sql: '${b.dim1}',
                    compiledSql: 'SUM(("b".dim1))',
                    compiledValueSql: '("b".dim1)',
                    source: sourceMock,
                    hidden: false,
                    tablesReferences: ['b'],
                    tablesRequiredAttributes: {
                        b: {
                            is_admin: 'true',
                        },
                    },
                    showUnderlyingValues: undefined,
                },
            },
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
            requiredAttributes: {
                is_admin: 'true',
            },
        },
    },
};
export const simpleJoinedExploreWithAlwaysTrue = {
    ...simpleJoinedExplore,
    joinedTables: [
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${b.dim1}',
            always: true,
        },
    ],
};
export const compiledSimpleJoinedExploreWithAlwaysTrue = {
    ...compiledSimpleJoinedExplore,
    joinedTables: [
        {
            table: 'b',
            sqlOn: '${a.dim1} = ${b.dim1}',
            compiledSqlOn: '("a".dim1) = ("b".dim1)',
            tablesReferences: ['a', 'b'],
            type: undefined,
            hidden: undefined,
            always: true,
            relationship: undefined,
        },
    ],
};
export const customSqlDimensionWithNoReferences = {
    id: 'test',
    name: 'Test',
    table: 'orders',
    type: CustomDimensionType.SQL,
    sql: '`orders`.`id`',
    dimensionType: DimensionType.STRING,
};
export const expectedCompiledCustomSqlDimensionWithNoReferences = {
    ...customSqlDimensionWithNoReferences,
    compiledSql: '`orders`.`id`',
    tablesReferences: [],
};
export const customSqlDimensionWithReferences = {
    id: 'test',
    name: 'Test',
    table: 'orders',
    type: CustomDimensionType.SQL,
    sql: '${a.dim1} + ${b.dim1}',
    dimensionType: DimensionType.STRING,
};
export const expectedCompiledCustomSqlDimensionWithReferences = {
    ...customSqlDimensionWithReferences,
    compiledSql: '("a".dim1) + ("b".dim1)',
    tablesReferences: ['a', 'b'],
};
// Simple mock data for parameter testing - reusing existing working mock structure
export const exploreWithParameters = {
    ...simpleJoinedExplore,
    name: 'explore_with_parameters',
    label: 'Explore with Parameters',
    joinedTables: [
        {
            table: 'b',
            sqlOn: "${a.dim1} = ${b.dim1} AND ${ld.parameters.b.active_status} = 'active'",
        },
    ],
    tables: {
        ...simpleJoinedExplore.tables,
        a: {
            ...simpleJoinedExplore.tables.a,
            parameters: {
                region: {
                    label: 'Region',
                    description: 'Filter by region',
                    default: 'US',
                },
            },
        },
        b: {
            ...simpleJoinedExplore.tables.b,
            parameters: {
                active_status: {
                    label: 'Active Status',
                    description: 'Define active status',
                    default: 'active',
                },
            },
        },
    },
};
export const compiledExploreWithParameters = {
    ...compiledSimpleJoinedExplore,
    name: 'explore_with_parameters',
    label: 'Explore with Parameters',
    joinedTables: [
        {
            table: 'b',
            sqlOn: "${a.dim1} = ${b.dim1} AND ${ld.parameters.b.active_status} = 'active'",
            compiledSqlOn: '("a".dim1) = ("b".dim1) AND ${ld.parameters.b.active_status} = \'active\'',
            tablesReferences: ['a', 'b'],
            parameterReferences: ['b.active_status'],
            type: undefined,
            hidden: undefined,
            always: undefined,
            relationship: undefined,
        },
    ],
    tables: {
        ...compiledSimpleJoinedExplore.tables,
        a: {
            ...compiledSimpleJoinedExplore.tables.a,
            parameters: {
                region: {
                    label: 'Region',
                    description: 'Filter by region',
                    default: 'US',
                },
            },
        },
        b: {
            ...compiledSimpleJoinedExplore.tables.b,
            parameters: {
                active_status: {
                    label: 'Active Status',
                    description: 'Define active status',
                    default: 'active',
                },
            },
        },
    },
};
export const exploreWithInvalidParameterReference = {
    ...simpleJoinedExplore,
    name: 'explore_with_invalid_params',
    label: 'Explore with Invalid Parameters',
    joinedTables: [
        {
            table: 'b',
            sqlOn: "${a.dim1} = ${b.dim1} AND ${ld.parameters.b.nonexistent_param} = 'active'",
        },
    ],
    tables: {
        ...simpleJoinedExplore.tables,
        a: {
            ...simpleJoinedExplore.tables.a,
            parameters: {},
        },
        b: {
            ...simpleJoinedExplore.tables.b,
            parameters: {
                valid_status: {
                    label: 'Valid Status',
                    description: 'A valid parameter',
                    default: 'active',
                },
            },
        },
    },
};
// Test data for join description overrides
export const simpleJoinedExploreWithBaseTableDescription = {
    ...simpleJoinedExplore,
    tables: {
        ...simpleJoinedExplore.tables,
        b: {
            ...simpleJoinedExplore.tables.b,
            description: 'Base table B description',
        },
    },
};
export const compiledSimpleJoinedExploreWithBaseTableDescription = {
    ...compiledSimpleJoinedExplore,
    tables: {
        ...compiledSimpleJoinedExplore.tables,
        b: {
            ...compiledSimpleJoinedExplore.tables.b,
            description: 'Base table B description',
        },
    },
};
export const joinedExploreOverridingJoinDescription = {
    ...simpleJoinedExplore,
    joinedTables: [
        {
            ...simpleJoinedExplore.joinedTables[0],
            description: 'Custom join description',
        },
    ],
    tables: {
        ...simpleJoinedExplore.tables,
        b: {
            ...simpleJoinedExplore.tables.b,
            description: 'Base table B description',
        },
    },
};
export const compiledJoinedExploreOverridingJoinDescription = {
    ...compiledSimpleJoinedExplore,
    tables: {
        ...compiledSimpleJoinedExplore.tables,
        b: {
            ...compiledSimpleJoinedExplore.tables.b,
            description: 'Custom join description',
        },
    },
};
/**
 * Test case for non-aggregate metric (type: NUMBER) that has aggregation
 * in SQL and references BOTH dimensions AND metrics. This pattern is common
 * in Looker where type:number measures have sql like "sum(${dim}) / ${metric}".
 */
export const exploreWithMixedDimensionAndMetricReferences = {
    ...exploreBase,
    baseTable: 'events',
    spotlightConfig: DEFAULT_SPOTLIGHT_CONFIG,
    meta: {},
    tables: {
        events: {
            name: 'events',
            label: 'events',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.events',
            sqlWhere: undefined,
            dimensions: {
                user_id: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.STRING,
                    name: 'user_id',
                    label: 'user_id',
                    table: 'events',
                    tableLabel: 'events',
                    sql: '${TABLE}.user_id',
                    source: sourceMock,
                    hidden: false,
                },
                amount: {
                    fieldType: FieldType.DIMENSION,
                    type: DimensionType.NUMBER,
                    name: 'amount',
                    label: 'amount',
                    table: 'events',
                    tableLabel: 'events',
                    sql: '${TABLE}.amount',
                    source: sourceMock,
                    hidden: false,
                },
            },
            metrics: {
                // Non-aggregate (NUMBER) metric with aggregation in SQL (Looker pattern)
                user_count: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.NUMBER,
                    name: 'user_count',
                    label: 'user_count',
                    table: 'events',
                    tableLabel: 'events',
                    sql: 'count(distinct ${user_id})',
                    source: sourceMock,
                    hidden: false,
                },
                // Non-aggregate (NUMBER) with BOTH dimension AND metric references
                // This pattern is: sum(${dim}) / ${metric}
                amount_per_user: {
                    fieldType: FieldType.METRIC,
                    type: MetricType.NUMBER,
                    name: 'amount_per_user',
                    label: 'amount_per_user',
                    table: 'events',
                    tableLabel: 'events',
                    sql: 'sum(${amount}) / NULLIF(${user_count}, 0)',
                    source: sourceMock,
                    hidden: false,
                },
            },
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
export const exploreWithMixedDimensionAndMetricReferencesCompiled = {
    name: exploreWithMixedDimensionAndMetricReferences.name,
    label: exploreWithMixedDimensionAndMetricReferences.label,
    baseTable: exploreWithMixedDimensionAndMetricReferences.baseTable,
    tags: exploreWithMixedDimensionAndMetricReferences.tags,
    targetDatabase: exploreWithMixedDimensionAndMetricReferences.targetDatabase,
    warehouse: exploreWithMixedDimensionAndMetricReferences.warehouse,
    ymlPath: exploreWithMixedDimensionAndMetricReferences.ymlPath,
    sqlPath: exploreWithMixedDimensionAndMetricReferences.sqlPath,
    groupLabel: exploreWithMixedDimensionAndMetricReferences.groupLabel,
    databricksCompute: exploreWithMixedDimensionAndMetricReferences.databricksCompute,
    spotlight: {
        visibility: 'show',
        categories: [],
    },
    joinedTables: [],
    tables: {
        events: {
            name: 'events',
            label: 'events',
            database: 'database',
            schema: 'schema',
            sqlTable: 'test.events',
            sqlWhere: undefined,
            uncompiledSqlWhere: undefined,
            dimensions: {
                user_id: {
                    ...exploreWithMixedDimensionAndMetricReferences.tables
                        .events.dimensions.user_id,
                    compiledSql: '"events".user_id',
                    tablesReferences: ['events'],
                },
                amount: {
                    ...exploreWithMixedDimensionAndMetricReferences.tables
                        .events.dimensions.amount,
                    compiledSql: '"events".amount',
                    tablesReferences: ['events'],
                },
            },
            metrics: {
                user_count: {
                    ...exploreWithMixedDimensionAndMetricReferences.tables
                        .events.metrics.user_count,
                    compiledSql: 'count(distinct ("events".user_id))',
                    compiledValueSql: 'count(distinct ("events".user_id))',
                    tablesReferences: ['events'],
                    showUnderlyingValues: undefined,
                },
                amount_per_user: {
                    ...exploreWithMixedDimensionAndMetricReferences.tables
                        .events.metrics.amount_per_user,
                    // amount is a dimension, user_count is a metric
                    compiledSql: 'sum(("events".amount)) / NULLIF((count(distinct ("events".user_id))), 0)',
                    compiledValueSql: 'sum(("events".amount)) / NULLIF((count(distinct ("events".user_id))), 0)',
                    tablesReferences: ['events'],
                    showUnderlyingValues: undefined,
                },
            },
            lineageGraph: {},
            groupLabel: undefined,
            source: sourceMock,
        },
    },
};
//# sourceMappingURL=exploreCompiler.mock.js.map