"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mockExploreWithJoinedTable = exports.mockExplore = exports.expectedRequiredResetResult = exports.baseTable = exports.joinedModelRequiredFilterRule = exports.modelRequiredFilterRule = exports.filterRule = exports.dimension = exports.expectedRequiredResult = exports.expectedFiltersWithCustomSqlDimension = exports.customSqlDimension = exports.expectedChartWithOverrideDashboardORFilters = exports.expectedChartWithOverrideDashboardFilters = exports.emptyDashboardFilters = exports.metricQueryWithExistingMetricFilters = exports.dashboardFiltersWithMetrics = exports.dashboardFilters = exports.metricQueryWithOrFilters = exports.metricQueryWithAndFilters = exports.dashboardFilterWithSameTargetButDifferentOperator = exports.dashboardFilterWithSameTargetAndOperator = exports.chartOrFilterGroup = exports.chartAndFilterGroup = void 0;
const dbt_1 = require("../types/dbt");
const field_1 = require("../types/field");
const filter_1 = require("../types/filter");
const table_1 = require("../types/table");
exports.chartAndFilterGroup = {
    id: 'fillter-group-1',
    and: [
        {
            id: '1',
            target: { fieldId: 'field-1' },
            values: ['1'],
            disabled: false,
            operator: filter_1.FilterOperator.EQUALS,
        },
        {
            id: '2',
            target: { fieldId: 'field-2' },
            values: ['2'],
            disabled: false,
            operator: filter_1.FilterOperator.EQUALS,
        },
    ],
};
exports.chartOrFilterGroup = {
    id: 'fillter-group-1',
    or: [
        {
            id: '3',
            target: { fieldId: 'field-1' },
            values: ['1'],
            disabled: false,
            operator: filter_1.FilterOperator.EQUALS,
        },
        {
            id: '4',
            target: { fieldId: 'field-2' },
            values: ['2'],
            disabled: false,
            operator: filter_1.FilterOperator.EQUALS,
        },
    ],
};
exports.dashboardFilterWithSameTargetAndOperator = [
    {
        id: '5',
        target: { fieldId: 'field-1' },
        values: ['1', '2', '3'],
        disabled: false,
        operator: filter_1.FilterOperator.EQUALS,
    },
];
exports.dashboardFilterWithSameTargetButDifferentOperator = [
    {
        id: '5',
        target: { fieldId: 'field-1' },
        values: ['1', '2', '3'],
        disabled: false,
        operator: filter_1.FilterOperator.NOT_EQUALS,
    },
];
exports.metricQueryWithAndFilters = {
    exploreName: 'test',
    limit: 501,
    dimensions: ['a_dim1'],
    metrics: [],
    sorts: [],
    tableCalculations: [],
    filters: {
        dimensions: {
            id: 'root',
            and: [
                {
                    id: '1',
                    target: {
                        fieldId: 'a_dim1',
                    },
                    operator: filter_1.FilterOperator.EQUALS,
                    values: [0],
                },
            ],
        },
    },
};
exports.metricQueryWithOrFilters = {
    exploreName: 'test',
    limit: 501,
    dimensions: ['a_dim1'],
    metrics: [],
    sorts: [],
    tableCalculations: [],
    filters: {
        dimensions: {
            id: 'root',
            or: [
                {
                    id: '1',
                    target: {
                        fieldId: 'a_dim1',
                    },
                    operator: filter_1.FilterOperator.EQUALS,
                    values: [0],
                },
            ],
        },
    },
};
exports.dashboardFilters = {
    dimensions: [
        {
            id: '4',
            label: undefined,
            target: {
                fieldId: 'a_dim1',
                tableName: 'test',
            },
            operator: filter_1.FilterOperator.EQUALS,
            values: ['1', '2', '3'],
        },
    ],
    metrics: [],
    tableCalculations: [],
};
exports.dashboardFiltersWithMetrics = {
    dimensions: [
        {
            id: '4',
            label: undefined,
            target: {
                fieldId: 'a_dim1',
                tableName: 'test',
            },
            operator: filter_1.FilterOperator.EQUALS,
            values: ['1', '2', '3'],
        },
    ],
    metrics: [
        {
            id: 'm1',
            label: undefined,
            target: {
                fieldId: 'a_metric1',
                tableName: 'test',
            },
            operator: filter_1.FilterOperator.GREATER_THAN,
            values: [100],
        },
    ],
    tableCalculations: [],
};
exports.metricQueryWithExistingMetricFilters = {
    exploreName: 'test',
    limit: 501,
    dimensions: ['a_dim1'],
    metrics: ['a_metric1'],
    sorts: [],
    tableCalculations: [],
    filters: {
        dimensions: {
            id: 'root',
            and: [
                {
                    id: '1',
                    target: {
                        fieldId: 'a_dim1',
                    },
                    operator: filter_1.FilterOperator.EQUALS,
                    values: [0],
                },
            ],
        },
        metrics: {
            id: 'metric-root',
            and: [
                {
                    id: 'existing-metric-filter',
                    target: {
                        fieldId: 'a_metric1',
                    },
                    operator: filter_1.FilterOperator.LESS_THAN,
                    values: [1000],
                },
            ],
        },
    },
};
exports.emptyDashboardFilters = {
    dimensions: [],
    metrics: [],
    tableCalculations: [],
};
exports.expectedChartWithOverrideDashboardFilters = {
    exploreName: 'test',
    dimensions: ['a_dim1'],
    limit: 501,
    metrics: [],
    sorts: [],
    tableCalculations: [],
    filters: {
        dimensions: {
            and: [
                {
                    id: '4',
                    target: {
                        fieldId: 'a_dim1',
                    },
                    operator: filter_1.FilterOperator.EQUALS,
                    values: ['1', '2', '3'],
                },
            ],
            id: 'uuid',
        },
        metrics: {
            and: [],
            id: 'uuid',
        },
        tableCalculations: {
            and: [],
            id: 'uuid',
        },
    },
};
exports.expectedChartWithOverrideDashboardORFilters = {
    exploreName: 'test',
    dimensions: ['a_dim1'],
    limit: 501,
    metrics: [],
    sorts: [],
    tableCalculations: [],
    filters: {
        dimensions: {
            and: [
                {
                    id: 'root',
                    or: [
                        {
                            id: '4',
                            target: {
                                fieldId: 'a_dim1',
                            },
                            operator: filter_1.FilterOperator.EQUALS,
                            values: ['1', '2', '3'],
                        },
                    ],
                },
            ],
            id: 'uuid',
        },
        metrics: {
            and: [],
            id: 'uuid',
        },
        tableCalculations: {
            and: [],
            id: 'uuid',
        },
    },
};
exports.customSqlDimension = {
    id: 'custom-sql-dimension',
    name: 'Custom SQL Dimension',
    table: 'custom_sql',
    type: field_1.CustomDimensionType.SQL,
    sql: '${table.field}',
    dimensionType: field_1.DimensionType.STRING,
};
exports.expectedFiltersWithCustomSqlDimension = {
    dimensions: {
        and: [
            {
                id: 'uuid',
                operator: filter_1.FilterOperator.EQUALS,
                target: {
                    fieldId: 'custom-sql-dimension',
                },
                values: [],
            },
        ],
        id: 'uuid',
    },
};
const expectedRequiredResult = (fieldIdRef, tableName) => ({
    id: 'uuid',
    target: {
        fieldId: `${tableName}_${fieldIdRef}`,
    },
    operator: filter_1.FilterOperator.IN_THE_NEXT,
    values: [14],
    settings: {
        unitOfTime: 'years',
    },
    required: true,
});
exports.expectedRequiredResult = expectedRequiredResult;
const dimension = (dimensionName, tableName) => ({
    fieldType: field_1.FieldType.DIMENSION,
    type: field_1.DimensionType.STRING,
    name: dimensionName,
    isIntervalBase: false,
    timeInterval: undefined,
    label: 'mockLabel',
    table: tableName,
    tableLabel: 'mockTableLabel',
    sql: 'mockSql',
    hidden: false,
});
exports.dimension = dimension;
exports.filterRule = {
    id: 'mockId',
    target: {
        fieldId: 'mockFieldId',
    },
    operator: filter_1.FilterOperator.IN_THE_NEXT,
    values: ['mockValue1', 'mockValue2'],
};
const modelRequiredFilterRule = (inputFieldRef) => ({
    id: 'uuid',
    operator: filter_1.FilterOperator.IN_THE_NEXT,
    settings: {
        unitOfTime: 'years',
    },
    target: {
        fieldRef: inputFieldRef,
    },
    values: [14],
});
exports.modelRequiredFilterRule = modelRequiredFilterRule;
const joinedModelRequiredFilterRule = (inputFieldRef, tableName) => {
    const requiredFilterRule = (0, exports.modelRequiredFilterRule)(inputFieldRef);
    return {
        ...requiredFilterRule,
        target: {
            ...requiredFilterRule.target,
            tableName,
        },
    };
};
exports.joinedModelRequiredFilterRule = joinedModelRequiredFilterRule;
exports.baseTable = {
    name: 'table',
    label: 'My table',
    database: 'database',
    schema: 'schema',
    sqlTable: '',
    description: '',
    sqlWhere: undefined,
    requiredAttributes: undefined,
    dimensions: {},
    metrics: {},
    orderFieldsBy: table_1.OrderFieldsByStrategy.LABEL,
    requiredFilters: [],
    groupLabel: undefined,
    groupDetails: {},
};
exports.expectedRequiredResetResult = {
    id: 'uuidGroup',
    and: [
        {
            id: 'uuid',
            target: {
                fieldId: 'table_mockFieldRef1',
            },
            operator: filter_1.FilterOperator.IN_THE_NEXT,
            values: [14],
            required: true,
            settings: {
                unitOfTime: 'years',
            },
        },
        {
            id: 'uuid',
            target: {
                fieldId: 'table_mockFieldRef2',
            },
            operator: filter_1.FilterOperator.IN_THE_NEXT,
            values: [14],
            required: false,
            settings: {
                unitOfTime: 'years',
            },
        },
    ],
};
exports.mockExplore = {
    name: 'test',
    label: 'Test',
    tags: [],
    baseTable: 'orders',
    targetDatabase: dbt_1.SupportedDbtAdapter.POSTGRES,
    joinedTables: [],
    tables: {
        orders: {
            name: 'orders',
            label: 'Orders',
            database: 'test',
            schema: 'public',
            sqlTable: 'orders',
            metrics: {},
            lineageGraph: {},
            dimensions: {
                // Interval base dimensions have isIntervalBase set and no
                // timeIntervalBaseDimensionName (see convertDimension in translator.ts)
                order_date: {
                    name: 'order_date',
                    label: 'Order Date',
                    table: 'orders',
                    tableLabel: 'Orders',
                    compiledSql: 'order_date',
                    tablesReferences: [],
                    sql: 'order_date',
                    hidden: false,
                    fieldType: field_1.FieldType.DIMENSION,
                    type: field_1.DimensionType.DATE,
                    isIntervalBase: true,
                },
                order_date_year: {
                    name: 'order_date_year',
                    label: 'Order Date Year',
                    table: 'orders',
                    tableLabel: 'Orders',
                    compiledSql: 'order_date_year',
                    tablesReferences: [],
                    sql: 'order_date_year',
                    hidden: false,
                    fieldType: field_1.FieldType.DIMENSION,
                    type: field_1.DimensionType.DATE,
                    timeIntervalBaseDimensionName: 'order_date',
                },
                order_date_month: {
                    name: 'order_date_month',
                    label: 'Order Date Month',
                    table: 'orders',
                    tableLabel: 'Orders',
                    compiledSql: 'order_date_month',
                    tablesReferences: [],
                    sql: 'order_date_month',
                    hidden: false,
                    fieldType: field_1.FieldType.DIMENSION,
                    type: field_1.DimensionType.DATE,
                    timeIntervalBaseDimensionName: 'order_date',
                },
                order_date_week: {
                    name: 'order_date_week',
                    label: 'Order Date Week',
                    table: 'orders',
                    tableLabel: 'Orders',
                    compiledSql: 'order_date_week',
                    sql: 'order_date_week',
                    hidden: false,
                    tablesReferences: [],
                    fieldType: field_1.FieldType.DIMENSION,
                    type: field_1.DimensionType.DATE,
                    timeIntervalBaseDimensionName: 'order_date',
                },
                status: {
                    name: 'status',
                    label: 'Status',
                    table: 'orders',
                    tableLabel: 'Orders',
                    compiledSql: 'status',
                    sql: 'status',
                    hidden: false,
                    tablesReferences: [],
                    fieldType: field_1.FieldType.DIMENSION,
                    type: field_1.DimensionType.BOOLEAN,
                },
            },
        },
    },
};
exports.mockExploreWithJoinedTable = {
    ...exports.mockExplore,
    tables: {
        orders: {
            ...exports.mockExplore.tables.orders,
            dimensions: {
                ...exports.mockExplore.tables.orders.dimensions,
                customer_id: {
                    name: 'customer_id',
                    label: 'Customer ID',
                    table: 'orders',
                    tableLabel: 'Orders',
                    compiledSql: 'customer_id',
                    sql: 'customer_id',
                    hidden: false,
                    fieldType: field_1.FieldType.DIMENSION,
                    type: field_1.DimensionType.NUMBER,
                    tablesReferences: [],
                },
            },
        },
        customers: {
            name: 'customers',
            label: 'Customers',
            database: 'test',
            schema: 'public',
            sqlTable: 'customers',
            metrics: {},
            lineageGraph: {},
            dimensions: {
                id: {
                    name: 'id',
                    label: 'ID',
                    table: 'customers',
                    tableLabel: 'Customers',
                    compiledSql: 'id',
                    tablesReferences: [],
                    fieldType: field_1.FieldType.DIMENSION,
                    type: field_1.DimensionType.STRING,
                    sql: 'id',
                    hidden: false,
                },
                created_at_week: {
                    name: 'created_at_week',
                    label: 'Created At Week',
                    table: 'customers',
                    tableLabel: 'Customers',
                    compiledSql: 'created_at_week',
                    sql: 'created_at_week',
                    hidden: false,
                    tablesReferences: [],
                    fieldType: field_1.FieldType.DIMENSION,
                    type: field_1.DimensionType.DATE,
                    timeIntervalBaseDimensionName: 'created_at',
                },
            },
        },
    },
    joinedTables: [
        {
            table: 'customers',
            sqlOn: '${orders.customer_id} = ${customers.id}',
            compiledSqlOn: '(orders.customer_id) = (customers.id)',
            type: undefined,
        },
    ],
};
//# sourceMappingURL=filters.mock.js.map