"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const zod_1 = require("zod");
const field_1 = require("../../../../types/field");
const filter_1 = require("../../../../types/filter");
const fieldId_1 = require("../fieldId");
const dateOrDateTimeSchema = zod_1.z.union([
    zod_1.z.string().date(),
    zod_1.z.string().datetime(),
]);
const commonDateFilterRuleSchema = zod_1.z.object({
    fieldId: (0, fieldId_1.getFieldIdSchema)({ additionalDescription: null }),
    fieldType: zod_1.z.union([
        zod_1.z.literal(field_1.DimensionType.DATE),
        zod_1.z.literal(field_1.DimensionType.TIMESTAMP),
        zod_1.z.literal(field_1.MetricType.DATE),
        zod_1.z.literal(field_1.MetricType.TIMESTAMP),
    ]),
    fieldFilterType: zod_1.z.literal(filter_1.FilterType.DATE),
});
const dateFilterSchema = zod_1.z.union([
    commonDateFilterRuleSchema.extend({
        operator: zod_1.z.union([
            zod_1.z.literal(filter_1.FilterOperator.NULL),
            zod_1.z.literal(filter_1.FilterOperator.NOT_NULL),
        ]),
    }),
    commonDateFilterRuleSchema.extend({
        operator: zod_1.z.union([
            zod_1.z.literal(filter_1.FilterOperator.EQUALS),
            zod_1.z.literal(filter_1.FilterOperator.NOT_EQUALS),
        ]),
        values: zod_1.z.array(dateOrDateTimeSchema),
    }),
    commonDateFilterRuleSchema.extend({
        operator: zod_1.z.union([
            zod_1.z.literal(filter_1.FilterOperator.IN_THE_PAST),
            zod_1.z.literal(filter_1.FilterOperator.NOT_IN_THE_PAST),
            zod_1.z.literal(filter_1.FilterOperator.IN_THE_NEXT),
            // NOTE: NOT_IN_THE_NEXT is not supported...
        ]),
        values: zod_1.z.array(zod_1.z.number()).length(1),
        settings: zod_1.z.object({
            completed: zod_1.z.boolean(),
            unitOfTime: zod_1.z.union([
                zod_1.z.literal(filter_1.UnitOfTime.days),
                zod_1.z.literal(filter_1.UnitOfTime.weeks),
                zod_1.z.literal(filter_1.UnitOfTime.months),
                zod_1.z.literal(filter_1.UnitOfTime.quarters),
                zod_1.z.literal(filter_1.UnitOfTime.years),
            ]),
        }),
    }),
    commonDateFilterRuleSchema.extend({
        operator: zod_1.z.union([
            zod_1.z.literal(filter_1.FilterOperator.IN_THE_CURRENT),
            zod_1.z.literal(filter_1.FilterOperator.NOT_IN_THE_CURRENT),
        ]),
        values: zod_1.z.array(zod_1.z.literal(1)).length(1),
        settings: zod_1.z.object({
            completed: zod_1.z.literal(false),
            unitOfTime: zod_1.z.union([
                zod_1.z.literal(filter_1.UnitOfTime.days),
                zod_1.z.literal(filter_1.UnitOfTime.weeks),
                zod_1.z.literal(filter_1.UnitOfTime.months),
                zod_1.z.literal(filter_1.UnitOfTime.quarters),
                zod_1.z.literal(filter_1.UnitOfTime.years),
            ]),
        }),
    }),
    commonDateFilterRuleSchema.extend({
        operator: zod_1.z.union([
            zod_1.z.literal(filter_1.FilterOperator.LESS_THAN),
            zod_1.z.literal(filter_1.FilterOperator.LESS_THAN_OR_EQUAL),
            zod_1.z.literal(filter_1.FilterOperator.GREATER_THAN),
            zod_1.z.literal(filter_1.FilterOperator.GREATER_THAN_OR_EQUAL),
        ]),
        values: zod_1.z.array(dateOrDateTimeSchema).length(1),
    }),
    commonDateFilterRuleSchema.extend({
        operator: zod_1.z.literal(filter_1.FilterOperator.IN_BETWEEN),
        values: zod_1.z.array(dateOrDateTimeSchema).length(2),
    }),
]);
exports.default = dateFilterSchema;
//# sourceMappingURL=dateFilters.js.map