"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomBBoxValidator = void 0;
class CustomBBoxValidator {
    static isLatitudeValid(latitude) {
        return latitude >= this.MIN_LATITUDE && latitude <= this.MAX_LATITUDE;
    }
    static isLongitudeValid(longitude) {
        return longitude >= this.MIN_LONGITUDE && longitude <= this.MAX_LONGITUDE;
    }
}
exports.CustomBBoxValidator = CustomBBoxValidator;
_a = CustomBBoxValidator;
/**
 * Bounding box format: topLat,topLon,bottomLat,bottomLon
 * 4 positive or negative floating point numbers separated by commas
 * @example 50.073619,14.414826,50.092867,14.438086
 */
CustomBBoxValidator.BOUNDING_BOX_REGEX = /^(?:-?\d+?(?:\.\d+?)?,){3}-?\d+?(?:\.\d+?)?$/;
/**
 * Redis/Valkey GEO commands support latitude values only in the range [-85.05112878, 85.05112878].
 *
 * See also:
 * <https://redis.io/docs/latest/commands/geoadd/#:~:text=Valid%20latitudes%20are%20from%20%2D85.05112878%20to%2085.05112878%20degrees.>,
 * <https://github.com/redis/redis/issues/13756>.
 */
CustomBBoxValidator.MIN_LATITUDE = -85.05112878;
CustomBBoxValidator.MAX_LATITUDE = 85.05112878;
CustomBBoxValidator.MIN_LONGITUDE = -180;
CustomBBoxValidator.MAX_LONGITUDE = 180;
CustomBBoxValidator.validate = (value, _) => {
    if (typeof value !== "string" || value.trim().length === 0 || value.length > 80 || !_a.BOUNDING_BOX_REGEX.test(value)) {
        return false;
    }
    const [topLat, topLon, bottomLat, bottomLon] = value.split(",").map((coordinate) => Number.parseFloat(coordinate));
    return (_a.isLatitudeValid(topLat) &&
        _a.isLatitudeValid(bottomLat) &&
        _a.isLongitudeValid(topLon) &&
        _a.isLongitudeValid(bottomLon));
};
//# sourceMappingURL=CustomBBoxValidator.js.map