"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateGetAnalytics = validateGetAnalytics;
const joi_1 = __importDefault(require("joi"));
const validator = __importStar(require("./validationWrapper.js"));
const ResourceInterface_ts_1 = require("../resources/ResourceInterface.js");
// A leaf condition. Both the canonical (attribute/comparator/value) and the
// legacy (search_attribute/search_type/search_value) names are accepted —
// `conformCondition` in resources/analytics/read.ts maps the latter onto the
// former.
const directConditionSchema = joi_1.default.object({
    attribute: joi_1.default.string(),
    search_attribute: joi_1.default.string(),
    comparator: joi_1.default.string().valid(...ResourceInterface_ts_1.COMPARATORS),
    search_type: joi_1.default.string().valid(...ResourceInterface_ts_1.COMPARATORS),
    value: joi_1.default.any(),
    search_value: joi_1.default.any(),
})
    .or('attribute', 'search_attribute')
    .or('comparator', 'search_type')
    .or('value', 'search_value');
// A condition group. The nested `conditions` array is left unconstrained for
// the same reason searchByConditionsSchema leaves it unconstrained: shallow
// validation here is enough to reject scalar/wrong-type inputs at the boundary.
const groupConditionSchema = joi_1.default.object({
    operator: joi_1.default.string().valid('and', 'or'),
    conditions: joi_1.default.array().required(),
});
// `.strict()` disables Joi's default type coercion so a numeric string like
// '1779834663816' is rejected for a `Joi.number()` field instead of being
// silently converted. Strictness propagates to child schemas.
const getAnalyticsSchema = joi_1.default.object({
    metric: joi_1.default.string().required(),
    start_time: joi_1.default.number().greater(0),
    end_time: joi_1.default.number().greater(0),
    get_attributes: joi_1.default.array().items(joi_1.default.string()),
    coalesce_time: joi_1.default.boolean(),
    conditions: joi_1.default.array().items(joi_1.default.alternatives(groupConditionSchema, directConditionSchema)),
    replicated: joi_1.default.boolean(),
}).strict();
function validateGetAnalytics(req) {
    return validator.validateBySchema(req, getAnalyticsSchema);
}
//# sourceMappingURL=analyticsValidator.js.map