"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveQueryTimezone = resolveQueryTimezone;
const errors_1 = require("../types/errors");
const scheduler_1 = require("./scheduler");
/**
 * Resolves the effective timezone for a query using the hierarchy:
 *   metricQuery.timezone → project timezone → 'UTC'
 *
 * The project timezone (from getQueryTimezoneForProject) already handles
 * the project → config → 'UTC' fallback, so this helper only adds the
 * per-chart override layer on top.
 *
 * Validates the resolved timezone to prevent SQL injection — the result
 * is interpolated into warehouse SQL strings (e.g., AT TIME ZONE '...').
 */
function resolveQueryTimezone(metricQuery, projectTimezone) {
    const timezone = metricQuery.timezone ?? projectTimezone;
    if (!(0, scheduler_1.isValidTimezone)(timezone)) {
        throw new errors_1.ParameterError(`Invalid timezone: ${timezone}`);
    }
    return timezone;
}
//# sourceMappingURL=resolveQueryTimezone.js.map